@base44-preview/sdk 0.8.17-pr.77.cbf4b6e → 0.8.17-pr.77.f633c05

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 CHANGED
@@ -167,9 +167,7 @@ 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 isOnLoginPage = typeof window !== "undefined" && window.location.pathname === "/login";
172
- if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) {
170
+ if (requiresAuth && typeof window !== "undefined") {
173
171
  // We perform this check asynchronously to not block client creation
174
172
  setTimeout(async () => {
175
173
  try {
@@ -25,16 +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
- // Skip redirect if already on login page to avoid redirect loop
29
- if (window.location.pathname === "/login") {
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) {
30
32
  return;
31
33
  }
32
34
  // If nextUrl is not provided, use the current URL
33
35
  const redirectUrl = nextUrl
34
36
  ? new URL(nextUrl, window.location.origin).toString()
35
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
+ }
36
45
  // Build the login URL
37
- const loginUrl = `${(_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : ""}/login?from_url=${encodeURIComponent(redirectUrl)}`;
46
+ const loginUrl = `${loginBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
38
47
  // Redirect to the login page
39
48
  window.location.href = loginUrl;
40
49
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.17-pr.77.cbf4b6e",
3
+ "version": "0.8.17-pr.77.f633c05",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",