@base44-preview/sdk 0.8.54-pr.344.ece486e → 0.8.55-pr.345.357a9ca

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,4 @@
1
+ import { getAccessToken, removeAccessToken } from "../utils/auth-utils.js";
1
2
  import { resetAnalyticsSessionContext } from "./analytics.js";
2
3
  function isInsideIframe() {
3
4
  if (typeof window === "undefined")
@@ -53,6 +54,21 @@ function loginViaPopup(url, redirectUrl, expectedOrigin) {
53
54
  }, 500);
54
55
  window.addEventListener("message", onMessage);
55
56
  }
57
+ // "token" is the key the platform-v2 built-in SDK wrote.
58
+ function removeStoredAccessTokens() {
59
+ removeAccessToken({});
60
+ removeAccessToken({ storageKey: "token" });
61
+ }
62
+ const isStoredAccessToken = (authorization) => authorization ===
63
+ `Bearer ${getAccessToken({ saveToStorage: false, removeFromUrl: false })}`;
64
+ // A rejected token left in storage boots the next page with it, and an app
65
+ // whose own /login does that loops 401 → /login. A token stored since the
66
+ // request went out (a login in this or another tab) is not the rejected one.
67
+ function clearTokenOnRejection(error, sentAuthorization) {
68
+ if (error.status === 401 && isStoredAccessToken(sentAuthorization)) {
69
+ removeStoredAccessTokens();
70
+ }
71
+ }
56
72
  /**
57
73
  * Creates the auth module for the Base44 SDK.
58
74
  *
@@ -88,7 +104,14 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
88
104
  },
89
105
  // Get current user information
90
106
  async me() {
91
- const request = pendingMe !== null && pendingMe !== void 0 ? pendingMe : axios.get(`/apps/${appId}/entities/User/me`).finally(() => {
107
+ const sentAuthorization = axios.defaults.headers.common["Authorization"];
108
+ const request = pendingMe !== null && pendingMe !== void 0 ? pendingMe : axios
109
+ .get(`/apps/${appId}/entities/User/me`)
110
+ .catch((error) => {
111
+ clearTokenOnRejection(error, sentAuthorization);
112
+ throw error;
113
+ })
114
+ .finally(() => {
92
115
  // Only retire this request if it is still the shared one. An identity
93
116
  // change mid-flight clears `pendingMe` and the next caller starts a
94
117
  // fresh request; an unconditional clear here would retire that newer
@@ -154,17 +177,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
154
177
  hasAccessToken = false;
155
178
  // Only do the rest if in a browser environment
156
179
  if (typeof window !== "undefined") {
157
- // Remove token from localStorage
158
- if (window.localStorage) {
159
- try {
160
- window.localStorage.removeItem("base44_access_token");
161
- // Remove "token" that is set by the built-in SDK of platform version 2
162
- window.localStorage.removeItem("token");
163
- }
164
- catch (e) {
165
- console.error("Failed to remove token from localStorage:", e);
166
- }
167
- }
180
+ removeStoredAccessTokens();
168
181
  // Determine the from_url parameter
169
182
  const fromUrl = redirectUrl || window.location.href;
170
183
  // Redirect to server-side logout endpoint to clear HTTP-only cookies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.54-pr.344.ece486e",
3
+ "version": "0.8.55-pr.345.357a9ca",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",