@base44-preview/sdk 0.8.17-pr.77.030ba28 → 0.8.17-pr.77.55f37b2
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/client.js +6 -2
- package/dist/modules/auth.js +14 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -167,8 +167,12 @@ export function createClient(config) {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
// If authentication is required, verify token and redirect to login if needed
|
|
170
|
-
// Skip if already on login page to avoid redirect loop
|
|
171
|
-
const
|
|
170
|
+
// Skip if already on login page to avoid redirect loop (but not on preview - preview should redirect to main)
|
|
171
|
+
const isPreview = typeof window !== "undefined" &&
|
|
172
|
+
window.location.hostname.startsWith("preview--");
|
|
173
|
+
const isOnLoginPage = typeof window !== "undefined" &&
|
|
174
|
+
window.location.pathname === "/login" &&
|
|
175
|
+
!isPreview;
|
|
172
176
|
if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) {
|
|
173
177
|
// We perform this check asynchronously to not block client creation
|
|
174
178
|
setTimeout(async () => {
|
package/dist/modules/auth.js
CHANGED
|
@@ -25,12 +25,25 @@ 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
|
+
const hostname = window.location.hostname;
|
|
29
|
+
const isPreview = hostname.startsWith("preview--");
|
|
30
|
+
// Skip redirect if already on login page (but not on preview - preview should redirect to main app)
|
|
31
|
+
if (window.location.pathname === "/login" && !isPreview) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
28
34
|
// If nextUrl is not provided, use the current URL
|
|
29
35
|
const redirectUrl = nextUrl
|
|
30
36
|
? new URL(nextUrl, window.location.origin).toString()
|
|
31
37
|
: window.location.href;
|
|
38
|
+
// For preview URLs (preview--*), redirect to main app's login page
|
|
39
|
+
// but keep from_url pointing to the preview URL
|
|
40
|
+
let loginBaseUrl = (_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : "";
|
|
41
|
+
if (isPreview) {
|
|
42
|
+
const mainHostname = hostname.replace(/^preview--/, "");
|
|
43
|
+
loginBaseUrl = `${window.location.protocol}//${mainHostname}${window.location.port ? ":" + window.location.port : ""}`;
|
|
44
|
+
}
|
|
32
45
|
// Build the login URL
|
|
33
|
-
const loginUrl = `${
|
|
46
|
+
const loginUrl = `${loginBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
34
47
|
// Redirect to the login page
|
|
35
48
|
window.location.href = loginUrl;
|
|
36
49
|
},
|