@@ -7,6 +7,10 @@ import { refreshAccessToken } from "./sessionRefresh";
77vi . mock ( "./sessionRefresh" , ( ) => ( { refreshAccessToken : vi . fn ( ) } ) ) ;
88const refreshMock = vi . mocked ( refreshAccessToken ) ;
99
10+ // Prod serves the API under /api (Traefik strips it); pin a base path so the exemptions are exercised
11+ // the way they run in prod — the GET /api/user probe must be exempt exactly like /user is locally.
12+ vi . mock ( "@/environment" , ( ) => ( { default : { serverUrl : "http://localhost/api" } } ) ) ;
13+
1014// jsdom's window.location is not directly assignable; replace it with a stub exposing `assign` plus
1115// the pathname/search/origin the handler reads.
1216function stubLocation ( pathname : string , search = "" ) : { assigned : string [ ] } {
@@ -130,6 +134,30 @@ describe("handlePossibleSessionExpiry", () => {
130134 expect ( assigned ) . toHaveLength ( 0 ) ;
131135 } ) ;
132136
137+ it ( "does NOT handle a 401 from the GET /api/user probe (prod /api base path)" , ( ) => {
138+ // A logged-out visitor on the public landing (pathname "/") probes the session; the /api-prefixed
139+ // probe must be exempt, not drive the login redirect.
140+ const { assigned } = stubLocation ( "/" ) ;
141+ const handled = handlePossibleSessionExpiry (
142+ res ( 401 , "http://localhost/api/user" ) ,
143+ makeQueryClient ( ) ,
144+ ) ;
145+ expect ( handled ) . toBe ( false ) ;
146+ expect ( refreshMock ) . not . toHaveBeenCalled ( ) ;
147+ expect ( assigned ) . toHaveLength ( 0 ) ;
148+ } ) ;
149+
150+ it ( "does NOT handle a 401 from /api/auth/* endpoints (prod /api base path)" , ( ) => {
151+ const { assigned } = stubLocation ( "/" ) ;
152+ const handled = handlePossibleSessionExpiry (
153+ res ( 401 , "http://localhost/api/auth/refresh" ) ,
154+ makeQueryClient ( ) ,
155+ ) ;
156+ expect ( handled ) . toBe ( false ) ;
157+ expect ( refreshMock ) . not . toHaveBeenCalled ( ) ;
158+ expect ( assigned ) . toHaveLength ( 0 ) ;
159+ } ) ;
160+
133161 it ( "does NOT handle a 401 from /auth/* endpoints (refresh must not recurse)" , ( ) => {
134162 const { assigned } = stubLocation ( "/" ) ;
135163 const handled = handlePossibleSessionExpiry (
0 commit comments