Skip to content

Commit

Permalink
feat(useSession): support custom session id generator (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
maou-shonen authored Jun 20, 2023
1 parent 2b2d596 commit 67e12ae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface SessionConfig {
sessionHeader?: false | string;
seal?: SealOptions;
crypto?: Crypto;
/** Default is Crypto.randomUUID */
generateId?: () => string;
}

const DEFAULT_NAME = "h3";
Expand Down Expand Up @@ -111,7 +113,8 @@ export async function getSession<T extends SessionDataT = SessionDataT>(

// New session store in response cookies
if (!session.id) {
session.id = (config.crypto || crypto).randomUUID();
session.id =
config.generateId?.() ?? (config.crypto || crypto).randomUUID();
session.createdAt = Date.now();
await updateSession(event, config);
}
Expand Down

0 comments on commit 67e12ae

Please sign in to comment.