@base44-preview/sdk 0.8.48-pr.282.8443e7d → 0.8.48-pr.282.c69fdcd
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/client.js +2 -14
- package/dist/modules/auth.js +7 -4
- package/dist/modules/auth.types.d.ts +5 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -58,10 +58,6 @@ export function createClient(config) {
|
|
|
58
58
|
const { serverUrl = "https://base44.app", appId, analytics, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
59
59
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
60
60
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
61
|
-
const inBrowser = typeof window !== "undefined";
|
|
62
|
-
// A host platform embeds the app with a one-time token on the iframe URL.
|
|
63
|
-
// It comes off the URL here, before any other code can read it; the
|
|
64
|
-
// exchange that turns it into a session runs once the modules exist.
|
|
65
61
|
const embedOtt = takeEmbedTokenFromUrl();
|
|
66
62
|
if (embedOtt) {
|
|
67
63
|
markEmbeddedTab();
|
|
@@ -71,7 +67,6 @@ export function createClient(config) {
|
|
|
71
67
|
// page loaded. In an embedded frame that is the one-time token itself, or a
|
|
72
68
|
// token an earlier visitor left in storage; neither is this session.
|
|
73
69
|
const token = embedded ? undefined : config.token;
|
|
74
|
-
let currentToken = token !== null && token !== void 0 ? token : null;
|
|
75
70
|
const socketConfig = {
|
|
76
71
|
serverUrl,
|
|
77
72
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -150,25 +145,18 @@ export function createClient(config) {
|
|
|
150
145
|
// request is built before setToken runs and goes out unauthenticated.
|
|
151
146
|
// An embedded load skips this: its session comes from the exchange below,
|
|
152
147
|
// and a token an earlier visitor left in storage must not become it.
|
|
153
|
-
if (
|
|
148
|
+
if (typeof window !== "undefined" && !embedded) {
|
|
154
149
|
const accessToken = token || getAccessToken();
|
|
155
150
|
if (accessToken) {
|
|
156
|
-
currentToken = accessToken;
|
|
157
151
|
userAuthModule.setToken(accessToken);
|
|
158
152
|
}
|
|
159
153
|
}
|
|
160
154
|
// The one answer every module reads. Follows setToken and logout; outside an
|
|
161
155
|
// embedded frame it still falls back to storage, so a login in another tab is
|
|
162
156
|
// picked up on the next connection, as before.
|
|
163
|
-
const getToken = () => {
|
|
164
|
-
if (userAuthModule.hasToken()) {
|
|
165
|
-
return currentToken;
|
|
166
|
-
}
|
|
167
|
-
return embedded ? null : getAccessToken();
|
|
168
|
-
};
|
|
157
|
+
const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
|
|
169
158
|
const applyToken = (newToken, saveToStorage) => {
|
|
170
159
|
userAuthModule.setToken(newToken, saveToStorage);
|
|
171
|
-
currentToken = newToken;
|
|
172
160
|
socketConfig.token = newToken;
|
|
173
161
|
if (socket) {
|
|
174
162
|
socket.updateConfig({ token: newToken });
|
package/dist/modules/auth.js
CHANGED
|
@@ -82,10 +82,13 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
82
82
|
// Tracked here rather than read off `axios.defaults` so the answer stays tied
|
|
83
83
|
// to the identity transitions below (`setToken`, `logout`) instead of to the
|
|
84
84
|
// header a caller may have set on the instance directly.
|
|
85
|
-
let
|
|
85
|
+
let accessToken = options.token || null;
|
|
86
86
|
return {
|
|
87
87
|
hasToken() {
|
|
88
|
-
return
|
|
88
|
+
return accessToken !== null;
|
|
89
|
+
},
|
|
90
|
+
getToken() {
|
|
91
|
+
return accessToken;
|
|
89
92
|
},
|
|
90
93
|
isEmbedded() {
|
|
91
94
|
return Boolean(options.embedded);
|
|
@@ -161,7 +164,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
161
164
|
// flight would otherwise resolve into callers that run after the logout.
|
|
162
165
|
clearPendingMe();
|
|
163
166
|
resetAnalyticsSessionContext();
|
|
164
|
-
|
|
167
|
+
accessToken = null;
|
|
165
168
|
// Only do the rest if in a browser environment
|
|
166
169
|
if (typeof window !== "undefined") {
|
|
167
170
|
// Remove token from localStorage
|
|
@@ -190,7 +193,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
190
193
|
// resolved for the previous one must not be handed to later callers.
|
|
191
194
|
clearPendingMe();
|
|
192
195
|
resetAnalyticsSessionContext();
|
|
193
|
-
|
|
196
|
+
accessToken = token;
|
|
194
197
|
// handle token change for axios clients
|
|
195
198
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
196
199
|
functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
@@ -560,4 +560,9 @@ export interface InternalAuthModule extends AuthModule {
|
|
|
560
560
|
* could not succeed without a session, not to decide that one is valid.
|
|
561
561
|
*/
|
|
562
562
|
hasToken(): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* The access token currently set on the client, or `null` when there is none.
|
|
565
|
+
* Follows {@linkcode AuthModule.setToken | setToken} and {@linkcode AuthModule.logout | logout}.
|
|
566
|
+
*/
|
|
567
|
+
getToken(): string | null;
|
|
563
568
|
}
|