-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
"@logto/next": minor | ||
--- | ||
|
||
support custom external session storage | ||
|
||
Add `sessionWrapper` to the config, you can implement your own session wrapper to support custom external session storage. | ||
|
||
Take a look at the example below: | ||
|
||
```ts | ||
import { MemorySessionWrapper } from './storage'; | ||
|
||
export const config = { | ||
// ... | ||
sessionWrapper: new MemorySessionWrapper(), | ||
}; | ||
``` | ||
|
||
```ts | ||
import { randomUUID } from 'node:crypto'; | ||
|
||
import { type SessionWrapper, type SessionData } from '@logto/next'; | ||
|
||
export class MemorySessionWrapper implements SessionWrapper { | ||
private readonly storage = new Map<string, unknown>(); | ||
|
||
async wrap(data: unknown, _key: string): Promise<string> { | ||
const sessionId = randomUUID(); | ||
this.storage.set(sessionId, data); | ||
return sessionId; | ||
} | ||
|
||
async unwrap(value: string, _key: string): Promise<SessionData> { | ||
if (!value) { | ||
return {}; | ||
} | ||
|
||
const data = this.storage.get(value); | ||
return data ?? {}; | ||
} | ||
} | ||
``` | ||
|
||
You can implement your own session wrapper to support custom external session storage like Redis, Memcached, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters