@@ -108,12 +108,17 @@ export async function niceBackendFetch(url: string | URL, options?: Omit<NiceReq
108108 accessType ?: null | "client" | "server" | "admin" ,
109109 body ?: unknown ,
110110 headers ?: Record < string , string | undefined > ,
111+ userAuth ?: {
112+ accessToken ?: string ,
113+ refreshToken ?: string ,
114+ } ,
111115} ) : Promise < NiceResponse > {
112- const { body, headers, accessType, ...otherOptions } = options ?? { } ;
116+ const { body, headers, accessType, userAuth : userAuthOverride , ...otherOptions } = options ?? { } ;
113117 if ( typeof body === "object" ) {
114118 expectSnakeCase ( body , "req.body" ) ;
115119 }
116- const { projectKeys, userAuth } = backendContext . value ;
120+ const projectKeys = backendContext . value . projectKeys ;
121+ const userAuth = userAuthOverride ?? backendContext . value . userAuth ;
117122 const fullUrl = new URL ( url , STACK_BACKEND_BASE_URL ) ;
118123 if ( fullUrl . origin !== new URL ( STACK_BACKEND_BASE_URL ) . origin ) throw new StackAssertionError ( `Invalid niceBackendFetch origin: ${ fullUrl . origin } ` ) ;
119124 if ( fullUrl . protocol !== new URL ( STACK_BACKEND_BASE_URL ) . protocol ) throw new StackAssertionError ( `Invalid niceBackendFetch protocol: ${ fullUrl . protocol } ` ) ;
@@ -207,9 +212,24 @@ export namespace Auth {
207212 const response = await niceBackendFetch ( "/api/v1/auth/sessions/current/refresh" , {
208213 method : "POST" ,
209214 accessType : "client" ,
210- headers : { "x-stack-access-token" : "" } ,
215+ userAuth : {
216+ refreshToken : backendContext . value . userAuth ?. refreshToken ,
217+ } ,
211218 } ) ;
212- expect ( response ) . toMatchInlineSnapshot ( ) ;
219+ expect ( response ) . toMatchInlineSnapshot ( `
220+ NiceResponse {
221+ "status": 401,
222+ "body": {
223+ "code": "ADMIN_ACCESS_TOKEN_EXPIRED",
224+ "details": { "expired_at_millis": 1756938402000 },
225+ "error": "Admin access token has expired. Please refresh it and try again. (The access token expired at 2025-09-03T22:26:42.000Z.)",
226+ },
227+ "headers": Headers {
228+ "x-stack-known-error": "ADMIN_ACCESS_TOKEN_EXPIRED",
229+ <some fields may have been hidden>,
230+ },
231+ }
232+ ` ) ;
213233 backendContext . set ( { userAuth : { accessToken : response . body . access_token , refreshToken : response . body . refresh_token } } ) ;
214234 await ensureParsableAccessToken ( ) ;
215235 return {
0 commit comments