@bid-scents/shared-sdk 1.1.1 → 1.1.2

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,4 +1,5 @@
1
1
  import type { User } from '../api/models/User';
2
+ import type { LoginResponse } from '../api/models/LoginResponse';
2
3
  interface AuthState {
3
4
  user: User | null;
4
5
  session: any | null;
@@ -9,6 +10,7 @@ interface AuthState {
9
10
  deviceToken: string | null;
10
11
  setUser: (user: User | null) => void;
11
12
  setSession: (session: any | null) => void;
13
+ setAuthState: (session: any | null, loginResponse: LoginResponse | null) => void;
12
14
  setLoading: (loading: boolean) => void;
13
15
  setError: (error: string | null) => void;
14
16
  logout: () => void;
@@ -20,6 +22,19 @@ interface AuthState {
20
22
  * Manages user data, session state, loading states, and errors.
21
23
  * Supabase automatically handles token refresh in the background.
22
24
  *
25
+ * ## Usage Guidelines:
26
+ *
27
+ * **For complete auth operations (login, OAuth, session establishment):**
28
+ * - Use `setAuthState(session, loginResponse)` - sets all auth state atomically
29
+ * - Prevents race conditions by updating isAuthenticated and isOnboarded together
30
+ *
31
+ * **For partial updates (profile edits, user data changes):**
32
+ * - Use `setUser(user)` - updates only user data without changing auth state
33
+ * - Use `setSession(session)` - updates only session without changing auth state
34
+ *
35
+ * **For clearing all auth state:**
36
+ * - Use `logout()` - clears everything atomically
37
+ *
23
38
  * @returns Auth store with user state, session, loading, and actions
24
39
  */
25
40
  export declare const useAuthStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthState>, "persist"> & {
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/stores/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAE9C,UAAU,SAAS;IACjB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAA;IACnB,eAAe,EAAE,OAAO,CA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EAAE,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,EAAE,aAAa,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAA;IAChF,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;CACrD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;EA0GxB,CAAA"}
@@ -7,6 +7,19 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
7
7
  * Manages user data, session state, loading states, and errors.
8
8
  * Supabase automatically handles token refresh in the background.
9
9
  *
10
+ * ## Usage Guidelines:
11
+ *
12
+ * **For complete auth operations (login, OAuth, session establishment):**
13
+ * - Use `setAuthState(session, loginResponse)` - sets all auth state atomically
14
+ * - Prevents race conditions by updating isAuthenticated and isOnboarded together
15
+ *
16
+ * **For partial updates (profile edits, user data changes):**
17
+ * - Use `setUser(user)` - updates only user data without changing auth state
18
+ * - Use `setSession(session)` - updates only session without changing auth state
19
+ *
20
+ * **For clearing all auth state:**
21
+ * - Use `logout()` - clears everything atomically
22
+ *
10
23
  * @returns Auth store with user state, session, loading, and actions
11
24
  */
12
25
  export const useAuthStore = create()(persist((set) => ({
@@ -18,28 +31,41 @@ export const useAuthStore = create()(persist((set) => ({
18
31
  error: null,
19
32
  deviceToken: null,
20
33
  /**
21
- * Updates the current user and onboarding status.
34
+ * Updates the current user only (without changing auth state).
35
+ * Use setAuthState() for complete auth state updates.
22
36
  *
23
37
  * @param user - User profile data or null to clear
24
38
  */
25
39
  setUser: (user) => {
26
40
  set({
27
41
  user,
28
- isOnboarded: !!user?.onboarded_at,
29
- loading: false, // Clear loading when user is set
30
42
  error: null // Clear any errors
31
43
  });
32
44
  },
33
45
  /**
34
- * Updates the Supabase session and authentication status.
46
+ * Updates the Supabase session only (without changing auth state).
47
+ * Use setAuthState() for complete auth state updates.
35
48
  *
36
49
  * @param session - Supabase session object containing tokens
37
50
  */
38
51
  setSession: (session) => {
52
+ set({ session });
53
+ },
54
+ /**
55
+ * Sets complete authentication state atomically from session and LoginResponse.
56
+ * This prevents race conditions by updating both auth and onboarding status together.
57
+ *
58
+ * @param session - Supabase session object or null
59
+ * @param loginResponse - API response containing onboarded status and user profile
60
+ */
61
+ setAuthState: (session, loginResponse) => {
39
62
  set({
40
63
  session,
41
64
  isAuthenticated: !!session,
42
- loading: false // Clear loading when session is determined
65
+ isOnboarded: loginResponse?.onboarded || false,
66
+ user: loginResponse?.profile || null,
67
+ loading: false,
68
+ error: null
43
69
  });
44
70
  },
45
71
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bid-scents/shared-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Shared SDK for marketplace applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",