@base44-preview/sdk 0.8.18-pr.123.a060ee3 → 0.8.18-pr.124.92d0a7a
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 +3 -1
- package/dist/modules/auth.js +19 -22
- package/dist/modules/auth.types.d.ts +2 -2
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -50,6 +50,8 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
50
50
|
*/
|
|
51
51
|
export function createClient(config) {
|
|
52
52
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
53
|
+
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
54
|
+
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
53
55
|
const socketConfig = {
|
|
54
56
|
serverUrl,
|
|
55
57
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -102,7 +104,7 @@ export function createClient(config) {
|
|
|
102
104
|
interceptResponses: false,
|
|
103
105
|
});
|
|
104
106
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
105
|
-
appBaseUrl,
|
|
107
|
+
appBaseUrl: normalizedAppBaseUrl,
|
|
106
108
|
serverUrl,
|
|
107
109
|
});
|
|
108
110
|
const userModules = {
|
package/dist/modules/auth.js
CHANGED
|
@@ -20,7 +20,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
20
20
|
},
|
|
21
21
|
// Redirects the user to the app's login page
|
|
22
22
|
redirectToLogin(nextUrl) {
|
|
23
|
-
var _a;
|
|
24
23
|
// This function only works in a browser environment
|
|
25
24
|
if (typeof window === "undefined") {
|
|
26
25
|
throw new Error("Login method can only be used in a browser environment");
|
|
@@ -30,7 +29,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
30
29
|
? new URL(nextUrl, window.location.origin).toString()
|
|
31
30
|
: window.location.href;
|
|
32
31
|
// Build the login URL
|
|
33
|
-
const loginUrl = `${
|
|
32
|
+
const loginUrl = `${options.appBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
34
33
|
// Redirect to the login page
|
|
35
34
|
window.location.href = loginUrl;
|
|
36
35
|
},
|
|
@@ -40,34 +39,32 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
40
39
|
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
41
40
|
// Build the provider login URL (google is the default, so no provider path needed)
|
|
42
41
|
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
43
|
-
const loginUrl = `${options.
|
|
42
|
+
const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
44
43
|
// Redirect to the provider login page
|
|
45
44
|
window.location.href = loginUrl;
|
|
46
45
|
},
|
|
47
46
|
// Logout the current user
|
|
48
|
-
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
49
47
|
logout(redirectUrl) {
|
|
50
|
-
// Remove token from axios headers
|
|
48
|
+
// Remove token from axios headers (always do this)
|
|
51
49
|
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
|
|
50
|
+
// Only do the rest if in a browser environment
|
|
64
51
|
if (typeof window !== "undefined") {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
52
|
+
// Remove token from localStorage
|
|
53
|
+
if (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
|
+
}
|
|
70
62
|
}
|
|
63
|
+
// Determine the from_url parameter
|
|
64
|
+
const fromUrl = redirectUrl || window.location.href;
|
|
65
|
+
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
66
|
+
const logoutUrl = `${options.appBaseUrl}/api/apps/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
67
|
+
window.location.href = logoutUrl;
|
|
71
68
|
}
|
|
72
69
|
},
|
|
73
70
|
// Set authentication token
|
|
@@ -90,8 +90,8 @@ export interface ResetPasswordParams {
|
|
|
90
90
|
export interface AuthModuleOptions {
|
|
91
91
|
/** Server URL for API requests. */
|
|
92
92
|
serverUrl: string;
|
|
93
|
-
/**
|
|
94
|
-
appBaseUrl
|
|
93
|
+
/** Base URL for the app (used for login redirects). */
|
|
94
|
+
appBaseUrl: string;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Authentication module for managing user authentication and authorization. The module automatically stores tokens in local storage when available and manages authorization headers for API requests.
|