Skip to content

Commit d29f221

Browse files
committed
add _id to session payload, fixes #24
1 parent 1ad021a commit d29f221

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Middleware.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function sessionMiddleware(options: SessionOptions): MiddlewareHandler {
4242
try {
4343
sid = (encryptionKey ? await decrypt(encryptionKey, sessionCookie) : sessionCookie) as string
4444
session_data = await store.getSessionById(sid)
45+
46+
if (session_data) {
47+
session_data._id = sid
48+
}
4549
} catch {
4650
createNewSession = true
4751
}
@@ -64,7 +68,7 @@ export function sessionMiddleware(options: SessionOptions): MiddlewareHandler {
6468
}
6569

6670
if (createNewSession) {
67-
const defaultData = {
71+
const defaultData : SessionData = {
6872
_data:{},
6973
_expire: null,
7074
_delete: false,
@@ -75,6 +79,7 @@ export function sessionMiddleware(options: SessionOptions): MiddlewareHandler {
7579
await store.createSession(c, defaultData)
7680
} else {
7781
sid = globalThis.crypto.randomUUID()
82+
defaultData._id = sid
7883
await store.createSession(sid, defaultData)
7984
}
8085

src/Session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface SessionDataEntry<T> {
44
}
55

66
export interface SessionData<T = any> {
7+
_id?: string, // No id used with cookie store
78
_data: Record<string, SessionDataEntry<T>>,
89
_expire: string | null,
910
_delete: boolean,

0 commit comments

Comments
 (0)