From 21de082249092183133c273ff740d1d32e2a1b03 Mon Sep 17 00:00:00 2001 From: eliorh Date: Mon, 12 Jan 2026 15:02:09 +0200 Subject: [PATCH 1/5] fix: prevent redirect loop when already on login page --- src/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 6b9448f..e27007a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,7 +197,11 @@ export function createClient(config: CreateClientConfig): Base44Client { } // If authentication is required, verify token and redirect to login if needed - if (requiresAuth && typeof window !== "undefined") { + // Skip if already on login page to avoid redirect loop + const isOnLoginPage = + typeof window !== "undefined" && window.location.pathname === "/login"; + + if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) { // We perform this check asynchronously to not block client creation setTimeout(async () => { try { From 4af0f871ccfd542914fc8e6f14ac9a7a402fa035 Mon Sep 17 00:00:00 2001 From: eliorh Date: Mon, 12 Jan 2026 15:35:40 +0200 Subject: [PATCH 2/5] fix: prevent redirect loop when already on login page --- src/modules/auth.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/auth.ts b/src/modules/auth.ts index 0736da2..df6c82a 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -43,6 +43,11 @@ export function createAuthModule( ); } + // Skip redirect if already on login page to avoid redirect loop + if (window.location.pathname === "/login") { + return; + } + // If nextUrl is not provided, use the current URL const redirectUrl = nextUrl ? new URL(nextUrl, window.location.origin).toString() From 87b7d6d1e46cbc083b8902896d3d488db8fb6900 Mon Sep 17 00:00:00 2001 From: eliorh Date: Mon, 12 Jan 2026 17:45:30 +0200 Subject: [PATCH 3/5] fix: update login URL handling for preview environments --- src/modules/auth.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/auth.ts b/src/modules/auth.ts index df6c82a..ac288a4 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -53,10 +53,21 @@ export function createAuthModule( ? new URL(nextUrl, window.location.origin).toString() : window.location.href; + // For preview URLs (preview--*), redirect to main app's login page + // but keep from_url pointing to the preview URL + let loginBaseUrl = options.appBaseUrl ?? ""; + const hostname = window.location.hostname; + if (hostname.startsWith("preview--")) { + const mainHostname = hostname.replace(/^preview--/, ""); + loginBaseUrl = `${window.location.protocol}//${mainHostname}${ + window.location.port ? ":" + window.location.port : "" + }`; + } + // Build the login URL - const loginUrl = `${ - options.appBaseUrl ?? "" - }/login?from_url=${encodeURIComponent(redirectUrl)}`; + const loginUrl = `${loginBaseUrl}/login?from_url=${encodeURIComponent( + redirectUrl + )}`; // Redirect to the login page window.location.href = loginUrl; From 2d265486a1857e456f3f391142ecb74b6fdd0c22 Mon Sep 17 00:00:00 2001 From: eliorh Date: Mon, 12 Jan 2026 18:18:33 +0200 Subject: [PATCH 4/5] fix: update login URL handling for preview environments --- src/client.ts | 9 +++++++-- src/modules/auth.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/client.ts b/src/client.ts index e27007a..e510d7c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,9 +197,14 @@ export function createClient(config: CreateClientConfig): Base44Client { } // If authentication is required, verify token and redirect to login if needed - // Skip if already on login page to avoid redirect loop + // Skip if already on login page to avoid redirect loop (but not on preview - preview should redirect to main) + const isPreview = + typeof window !== "undefined" && + window.location.hostname.startsWith("preview--"); const isOnLoginPage = - typeof window !== "undefined" && window.location.pathname === "/login"; + typeof window !== "undefined" && + window.location.pathname === "/login" && + !isPreview; if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) { // We perform this check asynchronously to not block client creation diff --git a/src/modules/auth.ts b/src/modules/auth.ts index ac288a4..aed6df0 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -43,8 +43,11 @@ export function createAuthModule( ); } - // Skip redirect if already on login page to avoid redirect loop - if (window.location.pathname === "/login") { + const hostname = window.location.hostname; + const isPreview = hostname.startsWith("preview--"); + + // Skip redirect if already on login page (but not on preview - preview should redirect to main app) + if (window.location.pathname === "/login" && !isPreview) { return; } @@ -56,8 +59,7 @@ export function createAuthModule( // For preview URLs (preview--*), redirect to main app's login page // but keep from_url pointing to the preview URL let loginBaseUrl = options.appBaseUrl ?? ""; - const hostname = window.location.hostname; - if (hostname.startsWith("preview--")) { + if (isPreview) { const mainHostname = hostname.replace(/^preview--/, ""); loginBaseUrl = `${window.location.protocol}//${mainHostname}${ window.location.port ? ":" + window.location.port : "" From 284f7ee2432f4fe87021d57bc48973962997782c Mon Sep 17 00:00:00 2001 From: eliorh Date: Mon, 12 Jan 2026 20:55:58 +0200 Subject: [PATCH 5/5] revert to main --- src/client.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/client.ts b/src/client.ts index e510d7c..6b9448f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,16 +197,7 @@ export function createClient(config: CreateClientConfig): Base44Client { } // If authentication is required, verify token and redirect to login if needed - // Skip if already on login page to avoid redirect loop (but not on preview - preview should redirect to main) - const isPreview = - typeof window !== "undefined" && - window.location.hostname.startsWith("preview--"); - const isOnLoginPage = - typeof window !== "undefined" && - window.location.pathname === "/login" && - !isPreview; - - if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) { + if (requiresAuth && typeof window !== "undefined") { // We perform this check asynchronously to not block client creation setTimeout(async () => { try {