@base44-preview/sdk 0.8.17-pr.77.030ba28 → 0.8.17-pr.77.dfc0f63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/auth.js +13 -1
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -25,12 +25,24 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
25
25
|
if (typeof window === "undefined") {
|
|
26
26
|
throw new Error("Login method can only be used in a browser environment");
|
|
27
27
|
}
|
|
28
|
+
// Skip redirect if already on login page to avoid redirect loop
|
|
29
|
+
if (window.location.pathname === "/login") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
28
32
|
// If nextUrl is not provided, use the current URL
|
|
29
33
|
const redirectUrl = nextUrl
|
|
30
34
|
? new URL(nextUrl, window.location.origin).toString()
|
|
31
35
|
: window.location.href;
|
|
36
|
+
// For preview URLs (preview--*), redirect to main app's login page
|
|
37
|
+
// but keep from_url pointing to the preview URL
|
|
38
|
+
let loginBaseUrl = (_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : "";
|
|
39
|
+
const hostname = window.location.hostname;
|
|
40
|
+
if (hostname.startsWith("preview--")) {
|
|
41
|
+
const mainHostname = hostname.replace(/^preview--/, "");
|
|
42
|
+
loginBaseUrl = `${window.location.protocol}//${mainHostname}${window.location.port ? ":" + window.location.port : ""}`;
|
|
43
|
+
}
|
|
32
44
|
// Build the login URL
|
|
33
|
-
const loginUrl = `${
|
|
45
|
+
const loginUrl = `${loginBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
34
46
|
// Redirect to the login page
|
|
35
47
|
window.location.href = loginUrl;
|
|
36
48
|
},
|