@base44-preview/sdk 0.8.19-pr.133.511000e → 0.8.19-pr.134.76a0e8e

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.
@@ -1,3 +1,60 @@
1
+ const POPUP_AUTH_DOMAIN_REGEX = /^(preview-sandbox--|preview--|checkpoint--)[^.]+\./;
2
+ function isPopupAuthDomain() {
3
+ if (typeof window === "undefined")
4
+ return false;
5
+ return POPUP_AUTH_DOMAIN_REGEX.test(window.location.hostname);
6
+ }
7
+ /**
8
+ * Opens a URL in a centered popup and waits for the backend to postMessage
9
+ * the auth result back. On success, redirects the current window to
10
+ * redirectUrl with the token params appended, preserving the same behaviour
11
+ * as a normal full-page redirect flow.
12
+ *
13
+ * @param url - The login URL to open in the popup (should include popup_origin).
14
+ * @param redirectUrl - Where to redirect after auth (the original fromUrl).
15
+ * @param expectedOrigin - The origin we expect the postMessage to come from.
16
+ */
17
+ function loginViaPopup(url, redirectUrl, expectedOrigin) {
18
+ const width = 500;
19
+ const height = 600;
20
+ const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
21
+ const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
22
+ const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
23
+ if (!popup) {
24
+ return;
25
+ }
26
+ const cleanup = () => {
27
+ window.removeEventListener("message", onMessage);
28
+ clearInterval(pollTimer);
29
+ if (!popup.closed)
30
+ popup.close();
31
+ };
32
+ const onMessage = (event) => {
33
+ var _a;
34
+ if (event.origin !== expectedOrigin)
35
+ return;
36
+ if (event.source !== popup)
37
+ return;
38
+ if (!((_a = event.data) === null || _a === void 0 ? void 0 : _a.access_token))
39
+ return;
40
+ cleanup();
41
+ // Append the token params to redirectUrl so the app processes them
42
+ // exactly as it would from a normal OAuth callback redirect.
43
+ const callbackUrl = new URL(redirectUrl);
44
+ const { access_token, is_new_user } = event.data;
45
+ callbackUrl.searchParams.set("access_token", access_token);
46
+ if (is_new_user != null) {
47
+ callbackUrl.searchParams.set("is_new_user", String(is_new_user));
48
+ }
49
+ window.location.href = callbackUrl.toString();
50
+ };
51
+ // Only used to detect the user closing the popup before auth completes
52
+ const pollTimer = setInterval(() => {
53
+ if (popup.closed)
54
+ cleanup();
55
+ }, 500);
56
+ window.addEventListener("message", onMessage);
57
+ }
1
58
  /**
2
59
  * Creates the auth module for the Base44 SDK.
3
60
  *
@@ -49,7 +106,13 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
49
106
  authPath = `/apps/auth${providerPath}/login`;
50
107
  }
51
108
  const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
52
- // Redirect to the provider login page
109
+ // On preview/sandbox/checkpoint domains the app runs inside an iframe —
110
+ // use a popup to avoid OAuth providers blocking iframe navigation.
111
+ if (isPopupAuthDomain()) {
112
+ const popupLoginUrl = `${loginUrl}&popup_origin=${encodeURIComponent(window.location.origin)}`;
113
+ return loginViaPopup(popupLoginUrl, redirectUrl, window.location.origin);
114
+ }
115
+ // Default: full-page redirect
53
116
  window.location.href = loginUrl;
54
117
  },
55
118
  // Logout the current user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.19-pr.133.511000e",
3
+ "version": "0.8.19-pr.134.76a0e8e",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",