@@ -49,7 +49,10 @@ describe('Ory proxy auth routes', () => {
4949 } )
5050
5151 it ( 'redirects authenticated users from sign-in to the dashboard' , async ( ) => {
52- authSession . current = { user : { id : 'user-id' } } as Session
52+ authSession . current = {
53+ user : { id : 'user-id' } ,
54+ accessToken : 'access-token' ,
55+ } as Session
5356
5457 const response = await proxy ( request ( '/sign-in' ) , { } as NextFetchEvent )
5558
@@ -69,9 +72,34 @@ describe('Ory proxy auth routes', () => {
6972 expect ( location ) . toContain ( 'returnTo=%2Fdashboard%2Fterminal' )
7073 } )
7174
75+ it ( 'treats sessions without an access token as unauthenticated on auth routes' , async ( ) => {
76+ authSession . current = {
77+ user : { id : 'user-id' } ,
78+ } as Session
79+
80+ const response = await proxy ( request ( '/sign-in' ) , { } as NextFetchEvent )
81+
82+ expect ( response . headers . get ( 'location' ) ) . toContain (
83+ '/api/auth/oauth-start?intent=signin'
84+ )
85+ } )
86+
87+ it ( 'treats sessions without a user id as unauthenticated on auth routes' , async ( ) => {
88+ authSession . current = {
89+ accessToken : 'access-token' ,
90+ } as Session
91+
92+ const response = await proxy ( request ( '/sign-in' ) , { } as NextFetchEvent )
93+
94+ expect ( response . headers . get ( 'location' ) ) . toContain (
95+ '/api/auth/oauth-start?intent=signin'
96+ )
97+ } )
98+
7299 it ( 'treats Auth.js error sessions as unauthenticated on auth routes' , async ( ) => {
73100 authSession . current = {
74101 user : { id : 'user-id' } ,
102+ accessToken : 'access-token' ,
75103 error : 'RefreshTokenError' ,
76104 } as Session
77105
0 commit comments