File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { eventHandler } from 'h3'
2
- import { requireUserSession , sessionHooks } from '../utils/session'
2
+ import { getUserSession , sessionHooks } from '../utils/session'
3
+ import type { UserSessionRequired } from '#auth-utils'
3
4
4
5
export default eventHandler ( async ( event ) => {
5
- const session = await requireUserSession ( event )
6
+ const session = await getUserSession ( event )
6
7
7
- await sessionHooks . callHookParallel ( 'fetch' , session , event )
8
+ if ( session . user ) {
9
+ await sessionHooks . callHookParallel ( 'fetch' , session as UserSessionRequired , event )
10
+ }
8
11
9
12
return session
10
13
} )
Original file line number Diff line number Diff line change @@ -20,4 +20,10 @@ describe('ssr', async () => {
20
20
const html = await $fetch ( '/' )
21
21
expect ( html ) . toContain ( '<div>Nuxt Auth Utils</div>' )
22
22
} )
23
+
24
+ it ( 'returns an empty session' , async ( ) => {
25
+ // Get response to a server-rendered page with `$fetch`.
26
+ const session = await $fetch ( '/api/_auth/session' )
27
+ expect ( session ) . toStrictEqual ( { } )
28
+ } )
23
29
} )
You can’t perform that action at this time.
0 commit comments