From f6cd01a0455554a6f36fd04ddc3807bcad2ec0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 5 Feb 2025 10:57:31 +0100 Subject: [PATCH 1/2] feat(session): add generated session id --- src/runtime/server/utils/session.ts | 6 +++++- src/runtime/types/session.ts | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runtime/server/utils/session.ts b/src/runtime/server/utils/session.ts index f98fc5bc..c6fa9099 100644 --- a/src/runtime/server/utils/session.ts +++ b/src/runtime/server/utils/session.ts @@ -28,7 +28,11 @@ export const sessionHooks = createHooks() * @returns The user session */ export async function getUserSession(event: UseSessionEvent) { - return (await _useSession(event)).data + const session = await _useSession(event) + return { + id: session.id, + ...session.data, + } } /** * Set a user session diff --git a/src/runtime/types/session.ts b/src/runtime/types/session.ts index e301da45..18940cf9 100644 --- a/src/runtime/types/session.ts +++ b/src/runtime/types/session.ts @@ -7,6 +7,10 @@ export interface SecureSessionData { } export interface UserSession { + /** + * Session ID + */ + id: string /** * User session data, available on client and server */ From 3591e3c7f2249eed1415a68aefcc9945116bef5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 5 Feb 2025 11:02:28 +0100 Subject: [PATCH 2/2] Update basic.test.ts --- test/basic.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/basic.test.ts b/test/basic.test.ts index d5e7311e..39380c67 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -24,6 +24,8 @@ describe('ssr', async () => { it('returns an empty session', async () => { // Get response to a server-rendered page with `$fetch`. const session = await $fetch('/api/_auth/session') - expect(session).toStrictEqual({}) + // Session should be an object with an `id` property + expect(session).toBeInstanceOf(Object) + expect(session).toHaveProperty('id') }) })