diff --git a/docs/pages/basics/sessions.md b/docs/pages/basics/sessions.md index 3631282a3..ecb880fa9 100644 --- a/docs/pages/basics/sessions.md +++ b/docs/pages/basics/sessions.md @@ -92,6 +92,16 @@ interface DatabaseSessionAttributes { } ``` +### Custom session IDs + +You use your own session IDs with the `sessionId` option, though we recommend sticking with Lucia's default IDs as they provide a good balance between entropy and compactness. If you're using UUIDs, make sure they're generated using a cryptographically secure random source. Object IDs should not be used as session IDs as they do not provide enough entropy. + +```ts +const session = await lucia.createSession(userId, attributes, { + sessionId: generate +}); +``` + ## Validate sessions Use `Lucia.validateSession()` to validate a session using its ID. This will return an object containing a session and user. Both of these will be `null` if the session is invalid. diff --git a/docs/pages/reference/main/Lucia/createSession.md b/docs/pages/reference/main/Lucia/createSession.md index 5424a2d92..2a4b577bd 100644 --- a/docs/pages/reference/main/Lucia/createSession.md +++ b/docs/pages/reference/main/Lucia/createSession.md @@ -14,7 +14,10 @@ Method of [`Lucia`](/reference/main/Lucia). Creates a new session. //$ UserId=/reference/main/UserId function createSession( userId: $$UserId, - attributes: $$DatabaseSessionAttributes + attributes: $$DatabaseSessionAttributes, + options?: { + sessionId?: string; + } ): Promise<$$Session>; ``` @@ -22,3 +25,5 @@ function createSession( - `userId` - `attributes`: Database session attributes +- `options`: + - `sessionId`