@@ -7,6 +7,7 @@ describe('Auth Module', () => {
77 let scope ;
88 const appId = 'test-app-id' ;
99 const serverUrl = 'https://api.base44.com' ;
10+ const appBaseUrl = 'https://api.base44.com' ;
1011
1112 beforeEach ( ( ) => {
1213 // Mock window.addEventListener and document for analytics module
@@ -27,6 +28,7 @@ describe('Auth Module', () => {
2728 base44 = createClient ( {
2829 serverUrl,
2930 appId,
31+ appBaseUrl,
3032 } ) ;
3133
3234 // Create a nock scope for mocking API calls
@@ -157,15 +159,15 @@ describe('Auth Module', () => {
157159 global . window = {
158160 location : mockLocation
159161 } ;
160-
162+
161163 const nextUrl = 'https://example.com/dashboard' ;
162164 base44 . auth . redirectToLogin ( nextUrl ) ;
163-
165+
164166 // Verify the redirect URL was set correctly
165167 expect ( mockLocation . href ) . toBe (
166- `/login?from_url=${ encodeURIComponent ( nextUrl ) } `
168+ `${ appBaseUrl } /login?from_url=${ encodeURIComponent ( nextUrl ) } `
167169 ) ;
168-
170+
169171 // Restore window
170172 global . window = originalWindow ;
171173 } ) ;
@@ -183,7 +185,7 @@ describe('Auth Module', () => {
183185
184186 // Verify the redirect URL uses current URL
185187 expect ( mockLocation . href ) . toBe (
186- `/login?from_url=${ encodeURIComponent ( currentUrl ) } `
188+ `${ appBaseUrl } /login?from_url=${ encodeURIComponent ( currentUrl ) } `
187189 ) ;
188190
189191 // Restore window
@@ -218,6 +220,12 @@ describe('Auth Module', () => {
218220 } ) ;
219221
220222 test ( 'should use relative URL for login redirect when appBaseUrl is not provided' , ( ) => {
223+ // Create a client without appBaseUrl
224+ const clientWithoutAppBaseUrl = createClient ( {
225+ serverUrl,
226+ appId,
227+ } ) ;
228+
221229 // Mock window.location
222230 const originalWindow = global . window ;
223231 const mockLocation = { href : '' , origin : 'https://current-app.com' } ;
@@ -226,7 +234,7 @@ describe('Auth Module', () => {
226234 } ;
227235
228236 const nextUrl = 'https://example.com/dashboard' ;
229- base44 . auth . redirectToLogin ( nextUrl ) ;
237+ clientWithoutAppBaseUrl . auth . redirectToLogin ( nextUrl ) ;
230238
231239 // Verify the redirect URL uses a relative path (no appBaseUrl prefix)
232240 expect ( mockLocation . href ) . toBe (
@@ -335,7 +343,7 @@ describe('Auth Module', () => {
335343 base44 . auth . logout ( redirectUrl ) ;
336344
337345 // Verify redirect to server-side logout endpoint with from_url parameter
338- const expectedUrl = `${ serverUrl } /api/apps/${ appId } /auth/logout?from_url=${ encodeURIComponent ( redirectUrl ) } ` ;
346+ const expectedUrl = `${ appBaseUrl } /api/apps/${ appId } /auth/logout?from_url=${ encodeURIComponent ( redirectUrl ) } ` ;
339347 expect ( mockLocation . href ) . toBe ( expectedUrl ) ;
340348
341349 // Restore window
@@ -354,7 +362,7 @@ describe('Auth Module', () => {
354362 base44 . auth . logout ( ) ;
355363
356364 // Verify redirect to server-side logout endpoint with current page as from_url
357- const expectedUrl = `${ serverUrl } /api/apps/${ appId } /auth/logout?from_url=${ encodeURIComponent ( 'https://example.com/current-page' ) } ` ;
365+ const expectedUrl = `${ appBaseUrl } /api/apps/${ appId } /auth/logout?from_url=${ encodeURIComponent ( 'https://example.com/current-page' ) } ` ;
358366 expect ( mockLocation . href ) . toBe ( expectedUrl ) ;
359367
360368 // Restore window
0 commit comments