From 2c3efa090af4764e8fd95c28c30751fe68838ebc Mon Sep 17 00:00:00 2001 From: pilcrow Date: Fri, 21 Jun 2024 23:02:02 +0900 Subject: [PATCH] Add docs on custom session IDs (#1609) --- docs/pages/basics/sessions.md | 10 ++++++++++ docs/pages/reference/main/Lucia/createSession.md | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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`