@mehdad67/apitogo 0.1.31 → 0.1.32

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/cli/cli.js CHANGED
@@ -4121,7 +4121,7 @@ import {
4121
4121
  // package.json
4122
4122
  var package_default = {
4123
4123
  name: "@mehdad67/apitogo",
4124
- version: "0.1.31",
4124
+ version: "0.1.32",
4125
4125
  type: "module",
4126
4126
  sideEffects: [
4127
4127
  "**/*.css",
@@ -4,28 +4,10 @@ export declare const useRefreshUserProfile: ({ refetchOnWindowFocus, }?: {
4
4
  refetchOnWindowFocus?: boolean | "always";
5
5
  }) => import("@tanstack/react-query").UseQueryResult<boolean | undefined, Error>;
6
6
  export declare const useVerifiedEmail: () => {
7
- email: string | undefined;
8
- isVerified: boolean | undefined;
7
+ email: any;
8
+ isVerified: any;
9
9
  supportsEmailVerification: boolean;
10
10
  refresh: () => undefined;
11
11
  requestEmailVerification: (options?: AuthActionOptions) => Promise<void>;
12
12
  };
13
- export declare const useAuth: () => {
14
- isBackendAvailable: boolean;
15
- authMode: import("./state.js").AuthMode;
16
- login: (options?: AuthActionOptions) => Promise<void>;
17
- logout: () => Promise<void>;
18
- signup: (options?: AuthActionOptions) => Promise<void>;
19
- requestEmailVerification: (options?: AuthActionOptions) => Promise<void>;
20
- isAuthenticated: boolean;
21
- isPending: boolean;
22
- profile: import("./state.js").UserProfile | null;
23
- providerData: import("./state.js").ProviderData | null;
24
- setAuthenticationPending: () => void;
25
- setLoggedOut: () => void;
26
- setLoggedIn: (args: {
27
- profile: import("./state.js").UserProfile;
28
- providerData: import("./state.js").ProviderData;
29
- }) => void;
30
- isAuthEnabled: boolean;
31
- };
13
+ export declare const useAuth: () => any;
@@ -16,32 +16,13 @@ export interface AuthState {
16
16
  providerData: ProviderData;
17
17
  }) => void;
18
18
  }
19
- export declare const authState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthState>, "setState" | "persist"> & {
20
- setState(partial: AuthState | Partial<AuthState> | ((state: AuthState) => AuthState | Partial<AuthState>), replace?: false | undefined): unknown;
21
- setState(state: AuthState | ((state: AuthState) => AuthState), replace: true): unknown;
22
- persist: {
23
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, unknown, unknown>>) => void;
24
- clearStorage: () => void;
25
- rehydrate: () => Promise<void> | void;
26
- hasHydrated: () => boolean;
27
- onHydrate: (fn: (state: AuthState) => void) => () => void;
28
- onFinishHydration: (fn: (state: AuthState) => void) => () => void;
29
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, unknown, unknown>>;
30
- };
31
- }>;
32
- export declare const useAuthState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthState>, "setState" | "persist"> & {
33
- setState(partial: AuthState | Partial<AuthState> | ((state: AuthState) => AuthState | Partial<AuthState>), replace?: false | undefined): unknown;
34
- setState(state: AuthState | ((state: AuthState) => AuthState), replace: true): unknown;
35
- persist: {
36
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, unknown, unknown>>) => void;
37
- clearStorage: () => void;
38
- rehydrate: () => Promise<void> | void;
39
- hasHydrated: () => boolean;
40
- onHydrate: (fn: (state: AuthState) => void) => () => void;
41
- onFinishHydration: (fn: (state: AuthState) => void) => () => void;
42
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, unknown, unknown>>;
43
- };
44
- }>;
19
+ type AuthStateStore = ReturnType<typeof createAuthStateStore>;
20
+ declare global {
21
+ var __APITOGO_AUTH_STATE: AuthStateStore | undefined;
22
+ }
23
+ declare function createAuthStateStore(): AuthStateStore;
24
+ export declare const authState: any;
25
+ export declare const useAuthState: any;
45
26
  export declare const waitForAuthStateHydration: () => Promise<void>;
46
27
  export interface UserProfile {
47
28
  sub: string;
@@ -51,3 +32,4 @@ export interface UserProfile {
51
32
  pictureUrl: string | undefined;
52
33
  [key: string]: string | boolean | undefined;
53
34
  }
35
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mehdad67/apitogo",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -40,67 +40,104 @@ export interface AuthState {
40
40
  }) => void;
41
41
  }
42
42
 
43
- export const authState = create<AuthState>()(
44
- persist(
45
- (set) => ({
46
- isAuthenticated: false,
47
- isPending: true,
48
- profile: null,
49
- providerData: null,
50
- isBackendAvailable: true,
51
- authMode: "live",
52
- setAuthenticationPending: () =>
53
- set(() => ({
54
- isAuthenticated: false,
55
- isPending: false,
56
- profile: null,
57
- providerData: null,
58
- isBackendAvailable: true,
59
- authMode: "live",
60
- })),
61
- setLoggedOut: () =>
62
- set(() => ({
63
- isAuthenticated: false,
64
- isPending: false,
65
- profile: null,
66
- providerData: null,
67
- isBackendAvailable: true,
68
- authMode: "live",
69
- })),
70
- setLoggedIn: ({ profile, providerData }) =>
71
- set(() => ({
72
- isAuthenticated: true,
73
- isPending: false,
74
- profile,
75
- providerData,
76
- })),
77
- }),
78
- {
79
- merge: (persistedState, currentState) => {
80
- const persisted =
81
- typeof persistedState === "object" && persistedState !== null
82
- ? (persistedState as Partial<AuthState>)
83
- : {};
84
-
85
- // Cookie/session auth is refreshed from the backend on load. Do not
86
- // restore identity fields from localStorage or OIDC return looks logged out.
87
- return {
88
- ...currentState,
89
- isPending: false,
90
- isBackendAvailable:
91
- persisted.isBackendAvailable ?? currentState.isBackendAvailable,
92
- authMode: persisted.authMode ?? currentState.authMode,
93
- };
94
- },
95
- partialize: (state) => ({
96
- isBackendAvailable: state.isBackendAvailable,
97
- authMode: state.authMode,
43
+ type AuthStateStore = ReturnType<typeof createAuthStateStore>;
44
+
45
+ /**
46
+ * Vite SSR/dev can load authentication modules more than once (app + plugins),
47
+ * which would otherwise create duplicate Zustand stores. The header would read
48
+ * one store while dev-portal auth writes another.
49
+ */
50
+ declare global {
51
+ var __APITOGO_AUTH_STATE: AuthStateStore | undefined;
52
+ }
53
+
54
+ function createAuthStateStore(): AuthStateStore {
55
+ return create<AuthState>()(
56
+ persist(
57
+ (set) => ({
58
+ isAuthenticated: false,
59
+ isPending: true,
60
+ profile: null,
61
+ providerData: null,
62
+ isBackendAvailable: true,
63
+ authMode: "live",
64
+ setAuthenticationPending: () =>
65
+ set(() => ({
66
+ isAuthenticated: false,
67
+ isPending: false,
68
+ profile: null,
69
+ providerData: null,
70
+ isBackendAvailable: true,
71
+ authMode: "live",
72
+ })),
73
+ setLoggedOut: () =>
74
+ set(() => ({
75
+ isAuthenticated: false,
76
+ isPending: false,
77
+ profile: null,
78
+ providerData: null,
79
+ isBackendAvailable: true,
80
+ authMode: "live",
81
+ })),
82
+ setLoggedIn: ({ profile, providerData }) =>
83
+ set(() => ({
84
+ isAuthenticated: true,
85
+ isPending: false,
86
+ profile,
87
+ providerData,
88
+ })),
98
89
  }),
99
- name: "auth-state",
100
- storage: createJSONStorage(() => localStorage),
101
- },
102
- ),
103
- );
90
+ {
91
+ version: 1,
92
+ migrate: (persistedState, version) => {
93
+ const persisted =
94
+ typeof persistedState === "object" && persistedState !== null
95
+ ? (persistedState as Partial<AuthState>)
96
+ : {};
97
+
98
+ // v0 stored full auth identity in localStorage; keep only backend metadata.
99
+ if (version === 0) {
100
+ return {
101
+ isBackendAvailable: persisted.isBackendAvailable,
102
+ authMode: persisted.authMode,
103
+ };
104
+ }
105
+
106
+ return persisted;
107
+ },
108
+ merge: (persistedState, currentState) => {
109
+ const persisted =
110
+ typeof persistedState === "object" && persistedState !== null
111
+ ? (persistedState as Partial<AuthState>)
112
+ : {};
113
+
114
+ // Cookie/session auth is refreshed from the backend on load. Do not
115
+ // restore identity fields from localStorage or OIDC return looks logged out.
116
+ return {
117
+ ...currentState,
118
+ isPending: false,
119
+ isAuthenticated: currentState.isAuthenticated,
120
+ profile: currentState.profile,
121
+ providerData: currentState.providerData,
122
+ isBackendAvailable:
123
+ persisted.isBackendAvailable ?? currentState.isBackendAvailable,
124
+ authMode: persisted.authMode ?? currentState.authMode,
125
+ };
126
+ },
127
+ partialize: (state) => ({
128
+ isBackendAvailable: state.isBackendAvailable,
129
+ authMode: state.authMode,
130
+ }),
131
+ name: "auth-state",
132
+ storage: createJSONStorage(() => localStorage),
133
+ },
134
+ ),
135
+ );
136
+ }
137
+
138
+ globalThis.__APITOGO_AUTH_STATE ??= createAuthStateStore();
139
+
140
+ export const authState = globalThis.__APITOGO_AUTH_STATE;
104
141
 
105
142
  syncZustandState(authState);
106
143
 
@@ -113,14 +150,21 @@ export const waitForAuthStateHydration = (): Promise<void> => {
113
150
  }
114
151
 
115
152
  const { persist } = useAuthState;
116
- if (persist.hasHydrated()) {
117
- return Promise.resolve();
118
- }
119
153
 
120
154
  return new Promise((resolve) => {
155
+ const finish = () => {
156
+ // Let hydration merge flush before /auth/me refresh runs.
157
+ queueMicrotask(resolve);
158
+ };
159
+
160
+ if (persist.hasHydrated()) {
161
+ finish();
162
+ return;
163
+ }
164
+
121
165
  const unsubscribe = persist.onFinishHydration(() => {
122
166
  unsubscribe();
123
- resolve();
167
+ finish();
124
168
  });
125
169
  });
126
170
  };