@@ -21,13 +21,15 @@ const runtimeConfig = {
2121 session : {
2222 skipHydratedSsrGetSession : false ,
2323 } ,
24+ redirects : { } as Record < string , unknown > ,
2425 } ,
2526 } ,
2627}
2728
2829const requestURL = { origin : 'http://localhost:3000' }
2930let requestHeaders : HeadersInit | undefined = { cookie : 'session=test' }
3031const state = new Map < string , ReturnType < typeof ref > > ( )
32+ const navigateTo = vi . fn ( async ( ) => { } )
3133
3234const sessionAtom = ref < SessionState > ( {
3335 data : null ,
@@ -55,6 +57,7 @@ vi.mock('#imports', async () => {
5557 const vue = await import ( 'vue' )
5658 return {
5759 computed : vue . computed ,
60+ navigateTo,
5861 nextTick : vue . nextTick ,
5962 watch : vue . watch ,
6063 useNuxtApp : ( ) => ( { payload } ) ,
@@ -96,6 +99,8 @@ describe('useUserSession hydration bootstrap', () => {
9699 requestURL . origin = 'http://localhost:3000'
97100 runtimeConfig . public . siteUrl = 'http://localhost:3000'
98101 runtimeConfig . public . auth . session . skipHydratedSsrGetSession = false
102+ runtimeConfig . public . auth . redirects = { }
103+ navigateTo . mockClear ( )
99104
100105 sessionAtom . value = {
101106 data : null ,
@@ -280,4 +285,37 @@ describe('useUserSession hydration bootstrap', () => {
280285 expect ( auth . session . value ) . toEqual ( { id : 'session-3' , ipAddress : '127.0.0.1' } )
281286 expect ( auth . user . value ) . toEqual ( { id : 'user-3' , email : 'user3@example.com' } )
282287 } )
288+
289+ it ( 'signOut navigates to redirects.logout when configured (and no onSuccess)' , async ( ) => {
290+ runtimeConfig . public . auth . redirects = { logout : '/logged-out' }
291+
292+ const useUserSession = await loadUseUserSession ( )
293+ const auth = useUserSession ( )
294+ await auth . signOut ( )
295+
296+ expect ( navigateTo ) . toHaveBeenCalledWith ( '/logged-out' )
297+ } )
298+
299+ it ( 'signOut does not auto-navigate when onSuccess is provided' , async ( ) => {
300+ runtimeConfig . public . auth . redirects = { logout : '/logged-out' }
301+
302+ const useUserSession = await loadUseUserSession ( )
303+ const auth = useUserSession ( )
304+
305+ const onSuccess = vi . fn ( )
306+ await auth . signOut ( { onSuccess } )
307+
308+ expect ( onSuccess ) . toHaveBeenCalledOnce ( )
309+ expect ( navigateTo ) . not . toHaveBeenCalled ( )
310+ } )
311+
312+ it ( 'signOut does not auto-navigate when redirects.logout is not configured' , async ( ) => {
313+ runtimeConfig . public . auth . redirects = { }
314+
315+ const useUserSession = await loadUseUserSession ( )
316+ const auth = useUserSession ( )
317+ await auth . signOut ( )
318+
319+ expect ( navigateTo ) . not . toHaveBeenCalled ( )
320+ } )
283321} )
0 commit comments