@base44-preview/sdk 0.8.24-pr.134.9c14bd3 → 0.8.24-pr.134.d84bc67

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.
@@ -57,7 +57,6 @@ function loginViaPopup(url, expectedOrigin, onToken) {
57
57
  */
58
58
  export function createAuthModule(axios, functionsAxiosClient, appId, options) {
59
59
  const listeners = new Set();
60
- let hasToken = false;
61
60
  function notify(event, data = {}) {
62
61
  listeners.forEach((cb) => cb(event, data));
63
62
  }
@@ -107,6 +106,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
107
106
  const popupLoginUrl = `${loginUrl}&popup_origin=${encodeURIComponent(window.location.origin)}`;
108
107
  return loginViaPopup(popupLoginUrl, window.location.origin, (token) => {
109
108
  this.setToken(token);
109
+ notify("SIGNED_IN", { access_token: token });
110
110
  });
111
111
  }
112
112
  // Default: full-page redirect
@@ -116,7 +116,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
116
116
  logout(redirectUrl) {
117
117
  // Remove token from axios headers (always do this)
118
118
  delete axios.defaults.headers.common["Authorization"];
119
- hasToken = false;
120
119
  notify("SIGNED_OUT");
121
120
  // Only do the rest if in a browser environment
122
121
  if (typeof window !== "undefined") {
@@ -142,7 +141,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
142
141
  setToken(token, saveToStorage = true) {
143
142
  if (!token)
144
143
  return;
145
- const event = hasToken ? "TOKEN_REFRESHED" : "SIGNED_IN";
146
144
  // handle token change for axios clients
147
145
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
148
146
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
@@ -159,8 +157,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
159
157
  console.error("Failed to save token to localStorage:", e);
160
158
  }
161
159
  }
162
- hasToken = true;
163
- notify(event, { access_token: token });
164
160
  },
165
161
  // Login using username and password
166
162
  async loginViaEmailPassword(email, password, turnstileToken) {
@@ -174,6 +170,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
174
170
  const { access_token, user } = response;
175
171
  if (access_token) {
176
172
  this.setToken(access_token);
173
+ notify("SIGNED_IN", { access_token });
177
174
  }
178
175
  return {
179
176
  access_token,
@@ -96,15 +96,13 @@ export interface AuthModuleOptions {
96
96
  /**
97
97
  * Auth state change event types.
98
98
  */
99
- export type AuthEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED";
99
+ export type AuthEvent = "SIGNED_IN" | "SIGNED_OUT";
100
100
  /**
101
101
  * Data passed to auth state change callbacks.
102
102
  */
103
103
  export interface AuthEventData {
104
104
  /** JWT access token, present on SIGNED_IN and TOKEN_REFRESHED events. */
105
105
  access_token?: string;
106
- /** User data, present on SIGNED_IN when available. */
107
- user?: User;
108
106
  }
109
107
  /**
110
108
  * Callback for auth state changes.
@@ -501,7 +499,6 @@ export interface AuthModule {
501
499
  * Events:
502
500
  * - `SIGNED_IN` — fired after a successful login (email/password, OAuth, or popup).
503
501
  * - `SIGNED_OUT` — fired after logout.
504
- * - `TOKEN_REFRESHED` — fired when `setToken` is called while already authenticated.
505
502
  *
506
503
  * Returns an unsubscribe function. Call it to stop receiving events.
507
504
  *
@@ -512,9 +509,10 @@ export interface AuthModule {
512
509
  * ```typescript
513
510
  * // In a React AuthContext provider
514
511
  * useEffect(() => {
515
- * const unsubscribe = base44.auth.onAuthStateChange((event, data) => {
512
+ * const unsubscribe = base44.auth.onAuthStateChange(async (event, data) => {
516
513
  * if (event === 'SIGNED_IN') {
517
- * setUser(data.user);
514
+ * const user = await base44.auth.me();
515
+ * setUser(user);
518
516
  * } else if (event === 'SIGNED_OUT') {
519
517
  * setUser(null);
520
518
  * }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.24-pr.134.9c14bd3",
3
+ "version": "0.8.24-pr.134.d84bc67",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",