@base44-preview/sdk 0.8.18-pr.90.f93cd0d → 0.8.18-pr.91.668781e
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 +18 -20
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -40,34 +40,32 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
40
40
|
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
41
41
|
// Build the provider login URL (google is the default, so no provider path needed)
|
|
42
42
|
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
43
|
-
const loginUrl = `${options.
|
|
43
|
+
const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
44
44
|
// Redirect to the provider login page
|
|
45
45
|
window.location.href = loginUrl;
|
|
46
46
|
},
|
|
47
47
|
// Logout the current user
|
|
48
|
-
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
49
48
|
logout(redirectUrl) {
|
|
50
|
-
// Remove token from axios headers
|
|
49
|
+
// Remove token from axios headers (always do this)
|
|
51
50
|
delete axios.defaults.headers.common["Authorization"];
|
|
52
|
-
//
|
|
53
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
54
|
-
try {
|
|
55
|
-
window.localStorage.removeItem("base44_access_token");
|
|
56
|
-
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
57
|
-
window.localStorage.removeItem("token");
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
console.error("Failed to remove token from localStorage:", e);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Redirect if a URL is provided
|
|
51
|
+
// Only do the rest if in a browser environment
|
|
64
52
|
if (typeof window !== "undefined") {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
// Remove token from localStorage
|
|
54
|
+
if (window.localStorage) {
|
|
55
|
+
try {
|
|
56
|
+
window.localStorage.removeItem("base44_access_token");
|
|
57
|
+
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
58
|
+
window.localStorage.removeItem("token");
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.error("Failed to remove token from localStorage:", e);
|
|
62
|
+
}
|
|
70
63
|
}
|
|
64
|
+
// Determine the from_url parameter
|
|
65
|
+
const fromUrl = redirectUrl || window.location.href;
|
|
66
|
+
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
67
|
+
const logoutUrl = `${options.appBaseUrl}/api/apps/${appId}/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
68
|
+
window.location.href = logoutUrl;
|
|
71
69
|
}
|
|
72
70
|
},
|
|
73
71
|
// Set authentication token
|