|
1 | 1 | import { AxiosInstance } from "axios"; |
| 2 | + |
| 3 | +import { removeAccessToken } from "../utils/auth-utils.js"; |
2 | 4 | import { |
3 | 5 | AuthModuleOptions, |
4 | 6 | InternalAuthModule, |
@@ -77,6 +79,12 @@ function loginViaPopup( |
77 | 79 | window.addEventListener("message", onMessage); |
78 | 80 | } |
79 | 81 |
|
| 82 | +// "token" is the key the platform-v2 built-in SDK wrote. |
| 83 | +function removeStoredAccessTokens() { |
| 84 | + removeAccessToken({}); |
| 85 | + removeAccessToken({ storageKey: "token" }); |
| 86 | +} |
| 87 | + |
80 | 88 | /** |
81 | 89 | * Creates the auth module for the Base44 SDK. |
82 | 90 | * |
@@ -155,7 +163,9 @@ export function createAuthModule( |
155 | 163 | // Build the login URL |
156 | 164 | const loginUrl = `${options.appBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`; |
157 | 165 |
|
158 | | - // Redirect to the login page |
| 166 | + // The login page must not boot with the token that just got us here, |
| 167 | + // or a rejected token redirects to /login forever. |
| 168 | + removeStoredAccessTokens(); |
159 | 169 | window.location.href = loginUrl; |
160 | 170 | }, |
161 | 171 |
|
@@ -202,16 +212,7 @@ export function createAuthModule( |
202 | 212 |
|
203 | 213 | // Only do the rest if in a browser environment |
204 | 214 | if (typeof window !== "undefined") { |
205 | | - // Remove token from localStorage |
206 | | - if (window.localStorage) { |
207 | | - try { |
208 | | - window.localStorage.removeItem("base44_access_token"); |
209 | | - // Remove "token" that is set by the built-in SDK of platform version 2 |
210 | | - window.localStorage.removeItem("token"); |
211 | | - } catch (e) { |
212 | | - console.error("Failed to remove token from localStorage:", e); |
213 | | - } |
214 | | - } |
| 215 | + removeStoredAccessTokens(); |
215 | 216 |
|
216 | 217 | // Determine the from_url parameter |
217 | 218 | const fromUrl = redirectUrl || window.location.href; |
|
0 commit comments