@base44-preview/sdk 0.8.19-pr.133.511000e → 0.8.19-pr.134.8e9c74b
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 +55 -12
- package/dist/modules/auth.types.d.ts +1 -8
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
const POPUP_AUTH_DOMAIN_REGEX = /^(preview-sandbox--|preview--|checkpoint--)[^.]+\.base44\.app$/;
|
|
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, once the OAuth provider redirects
|
|
9
|
+
* back to our origin, mirrors that callback URL in the current window so the
|
|
10
|
+
* iframe processes the access_token query param exactly as a normal redirect
|
|
11
|
+
* would.
|
|
12
|
+
*
|
|
13
|
+
* @param url - The URL to open in the popup.
|
|
14
|
+
*/
|
|
15
|
+
function loginViaPopup(url) {
|
|
16
|
+
const width = 500;
|
|
17
|
+
const height = 600;
|
|
18
|
+
const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
|
|
19
|
+
const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
|
|
20
|
+
const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
|
|
21
|
+
if (!popup) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const pollTimer = setInterval(() => {
|
|
25
|
+
if (popup.closed) {
|
|
26
|
+
clearInterval(pollTimer);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// Accessing popup.location.href throws a cross-origin error while the
|
|
31
|
+
// OAuth provider's pages are open — that's expected and means the flow
|
|
32
|
+
// is still in progress. Once it stops throwing, the popup has landed
|
|
33
|
+
// back on our origin with the callback URL (e.g. ?access_token=...).
|
|
34
|
+
const callbackUrl = popup.location.href;
|
|
35
|
+
if (new URL(callbackUrl).origin === window.location.origin) {
|
|
36
|
+
clearInterval(pollTimer);
|
|
37
|
+
popup.close();
|
|
38
|
+
// Redirect the iframe to the same URL the popup landed on so it
|
|
39
|
+
// processes the token from the query params as it normally would.
|
|
40
|
+
window.location.href = callbackUrl;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
// Still on the OAuth provider's domain — keep polling
|
|
45
|
+
}
|
|
46
|
+
}, 300);
|
|
47
|
+
}
|
|
1
48
|
/**
|
|
2
49
|
* Creates the auth module for the Base44 SDK.
|
|
3
50
|
*
|
|
@@ -37,19 +84,15 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
37
84
|
loginWithProvider(provider, fromUrl = "/") {
|
|
38
85
|
// Build the full redirect URL
|
|
39
86
|
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// Google is the default provider, so no provider path segment needed
|
|
48
|
-
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
49
|
-
authPath = `/apps/auth${providerPath}/login`;
|
|
87
|
+
// Build the provider login URL (google is the default, so no provider path needed)
|
|
88
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
89
|
+
const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
90
|
+
// On preview/sandbox/checkpoint domains the app runs inside an iframe —
|
|
91
|
+
// use a popup to avoid OAuth providers blocking iframe navigation.
|
|
92
|
+
if (isPopupAuthDomain()) {
|
|
93
|
+
return loginViaPopup(loginUrl);
|
|
50
94
|
}
|
|
51
|
-
|
|
52
|
-
// Redirect to the provider login page
|
|
95
|
+
// Default: full-page redirect
|
|
53
96
|
window.location.href = loginUrl;
|
|
54
97
|
},
|
|
55
98
|
// Logout the current user
|
|
@@ -185,9 +185,8 @@ export interface AuthModule {
|
|
|
185
185
|
* - `'microsoft'` - {@link https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow | Microsoft OAuth}. Enable Microsoft in your app's authentication settings before specifying this provider.
|
|
186
186
|
* - `'facebook'` - {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using.
|
|
187
187
|
* - `'apple'` - {@link https://developer.apple.com/sign-in-with-apple/ | Sign in with Apple}. Enable Apple in your app's authentication settings before using this provider.
|
|
188
|
-
* - `'sso'` - Enterprise SSO. Enable SSO in your app's authentication settings before using this provider.
|
|
189
188
|
*
|
|
190
|
-
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`,
|
|
189
|
+
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, or `'apple'`.
|
|
191
190
|
* @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
|
|
192
191
|
*
|
|
193
192
|
* @example
|
|
@@ -207,12 +206,6 @@ export interface AuthModule {
|
|
|
207
206
|
* // Apple
|
|
208
207
|
* base44.auth.loginWithProvider('apple', '/dashboard');
|
|
209
208
|
* ```
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* // SSO
|
|
214
|
-
* base44.auth.loginWithProvider('sso', '/dashboard');
|
|
215
|
-
* ```
|
|
216
209
|
*/
|
|
217
210
|
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
218
211
|
/**
|