@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
|
@@ -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:
|
|
8
|
-
isVerified:
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
@@ -40,67 +40,104 @@ export interface AuthState {
|
|
|
40
40
|
}) => void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
167
|
+
finish();
|
|
124
168
|
});
|
|
125
169
|
});
|
|
126
170
|
};
|