@@ -7,7 +7,7 @@ import { createServerFn } from '@tanstack/react-start';
77import { getRequestHeader } from '@tanstack/react-start/server' ;
88import type * as t from '@/types' ;
99import { useAppSession , SESSION_CONFIG } from './session' ;
10- import { getApiBaseUrl } from './utils/api' ;
10+ import { getApiBaseUrl , getServerApiUrl } from './utils/api' ;
1111
1212/** Extract a named cookie value from `set-cookie` response headers. */
1313function extractCookieValue ( response : Response , name : string ) : string | undefined {
@@ -29,7 +29,7 @@ export const adminLoginFn = createServerFn({ method: 'POST' })
2929 )
3030 . handler ( async ( { data } ) => {
3131 try {
32- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/admin/login/local` , {
32+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/admin/login/local` , {
3333 method : 'POST' ,
3434 headers : { 'Content-Type' : 'application/json' } ,
3535 body : JSON . stringify ( data ) ,
@@ -93,7 +93,7 @@ export const adminVerify2FAFn = createServerFn({ method: 'POST' })
9393 )
9494 . handler ( async ( { data } ) => {
9595 try {
96- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/auth/2fa/verify-temp` , {
96+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/auth/2fa/verify-temp` , {
9797 method : 'POST' ,
9898 headers : { 'Content-Type' : 'application/json' } ,
9999 body : JSON . stringify ( { tempToken : data . tempToken , token : data . totpCode } ) ,
@@ -170,7 +170,7 @@ async function refreshAdminToken(
170170 cookieParts . push ( 'token_provider=openid' ) ;
171171 }
172172
173- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/auth/refresh` , {
173+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/auth/refresh` , {
174174 method : 'POST' ,
175175 headers : { Cookie : cookieParts . join ( '; ' ) } ,
176176 } ) ;
@@ -216,7 +216,7 @@ export const verifyAdminTokenFn = createServerFn({ method: 'GET' }).handler(asyn
216216
217217 if ( needsRevalidation ) {
218218 try {
219- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/admin/verify` , {
219+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/admin/verify` , {
220220 headers : { Authorization : `Bearer ${ token } ` } ,
221221 } ) ;
222222
@@ -236,7 +236,7 @@ export const verifyAdminTokenFn = createServerFn({ method: 'GET' }).handler(asyn
236236 lastActivity : now ,
237237 } ;
238238 try {
239- const reVerify = await fetch ( `${ getApiBaseUrl ( ) } /api/admin/verify` , {
239+ const reVerify = await fetch ( `${ getServerApiUrl ( ) } /api/admin/verify` , {
240240 headers : { Authorization : `Bearer ${ refreshed . token } ` } ,
241241 } ) ;
242242 if ( reVerify . ok ) {
@@ -305,7 +305,7 @@ export const adminLogoutFn = createServerFn({ method: 'POST' }).handler(async ()
305305
306306 if ( token ) {
307307 try {
308- await fetch ( `${ getApiBaseUrl ( ) } /api/auth/logout` , {
308+ await fetch ( `${ getServerApiUrl ( ) } /api/auth/logout` , {
309309 method : 'POST' ,
310310 headers : { Authorization : `Bearer ${ token } ` } ,
311311 } ) ;
@@ -340,7 +340,7 @@ export const openIdCheckOptions = queryOptions({
340340
341341export const checkOpenIdFn = createServerFn ( { method : 'GET' } ) . handler ( async ( ) => {
342342 try {
343- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/admin/oauth/openid/check` ) ;
343+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/admin/oauth/openid/check` ) ;
344344 if ( ! response . ok ) return { available : false , ssoOnly : false } ;
345345 const ssoOnly = process . env . ADMIN_SSO_ONLY === 'true' ;
346346 return { available : true , ssoOnly } ;
@@ -389,7 +389,7 @@ export const oauthExchangeFn = createServerFn({ method: 'POST' })
389389 const session = await useAppSession ( ) ;
390390 const { codeVerifier } = session . data ;
391391
392- const response = await fetch ( `${ getApiBaseUrl ( ) } /api/admin/oauth/exchange` , {
392+ const response = await fetch ( `${ getServerApiUrl ( ) } /api/admin/oauth/exchange` , {
393393 method : 'POST' ,
394394 headers,
395395 body : JSON . stringify ( { code : data . code , code_verifier : codeVerifier } ) ,
0 commit comments