Skip to content

Commit

Permalink
feat(session): add generated session id (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Feb 5, 2025
1 parent 1e99757 commit f9d8e13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/runtime/server/utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const sessionHooks = createHooks<SessionHooks>()
* @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
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export interface SecureSessionData {
}

export interface UserSession {
/**
* Session ID
*/
id: string
/**
* User session data, available on client and server
*/
Expand Down
4 changes: 3 additions & 1 deletion test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit f9d8e13

Please sign in to comment.