@base44-preview/sdk 0.8.18-pr.90.f93cd0d → 0.8.18-pr.91.87dab3a
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 +17 -19
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -45,29 +45,27 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
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.serverUrl}/api/apps/${appId}/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
68
|
+
window.location.href = logoutUrl;
|
|
71
69
|
}
|
|
72
70
|
},
|
|
73
71
|
// Set authentication token
|