Skip to content

Commit

Permalink
Add docs on custom session IDs (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowOnPaper committed Jun 21, 2024
1 parent 10fab22 commit 2c3efa0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/pages/basics/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/reference/main/Lucia/createSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ 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>;
```

### Parameters

- `userId`
- `attributes`: Database session attributes
- `options`:
- `sessionId`

0 comments on commit 2c3efa0

Please sign in to comment.