Skip to content

Commit f9d8e13

Browse files
authored
feat(session): add generated session id (#338)
1 parent 1e99757 commit f9d8e13

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/runtime/server/utils/session.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export const sessionHooks = createHooks<SessionHooks>()
2828
* @returns The user session
2929
*/
3030
export async function getUserSession(event: UseSessionEvent) {
31-
return (await _useSession(event)).data
31+
const session = await _useSession(event)
32+
return {
33+
id: session.id,
34+
...session.data,
35+
}
3236
}
3337
/**
3438
* Set a user session

src/runtime/types/session.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export interface SecureSessionData {
77
}
88

99
export interface UserSession {
10+
/**
11+
* Session ID
12+
*/
13+
id: string
1014
/**
1115
* User session data, available on client and server
1216
*/

test/basic.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe('ssr', async () => {
2424
it('returns an empty session', async () => {
2525
// Get response to a server-rendered page with `$fetch`.
2626
const session = await $fetch('/api/_auth/session')
27-
expect(session).toStrictEqual({})
27+
// Session should be an object with an `id` property
28+
expect(session).toBeInstanceOf(Object)
29+
expect(session).toHaveProperty('id')
2830
})
2931
})

0 commit comments

Comments
 (0)