@bymax-one/nest-auth 1.1.0 → 1.2.0
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/CHANGELOG.md +141 -1
- package/README.md +75 -5
- package/dist/client/index.cjs +8 -1
- package/dist/client/index.mjs +8 -1
- package/dist/nextjs/index.cjs +7 -17
- package/dist/nextjs/index.d.cts +27 -8
- package/dist/nextjs/index.d.ts +27 -8
- package/dist/nextjs/index.mjs +7 -17
- package/dist/react/index.cjs +8 -0
- package/dist/react/index.mjs +8 -0
- package/dist/server/index.cjs +928 -363
- package/dist/server/index.d.cts +344 -81
- package/dist/server/index.d.ts +344 -81
- package/dist/server/index.mjs +928 -363
- package/package.json +4 -14
package/dist/react/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
50
50
|
const onSessionExpiredRef = useRef(onSessionExpired);
|
|
51
51
|
const clientRef = useRef(client);
|
|
52
52
|
const statusRef = useRef(INITIAL_STATE.status);
|
|
53
|
+
const sessionGenerationRef = useRef({});
|
|
53
54
|
useEffect(() => {
|
|
54
55
|
onSessionExpiredRef.current = onSessionExpired;
|
|
55
56
|
}, [
|
|
@@ -77,8 +78,10 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
77
78
|
}
|
|
78
79
|
}, []);
|
|
79
80
|
const revalidate = useCallback(async (isInitial) => {
|
|
81
|
+
const generation = sessionGenerationRef.current;
|
|
80
82
|
try {
|
|
81
83
|
const user = await clientRef.current.getMe();
|
|
84
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
82
85
|
syncedDispatch({
|
|
83
86
|
type: "SET_USER",
|
|
84
87
|
payload: {
|
|
@@ -87,6 +90,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
87
90
|
}
|
|
88
91
|
});
|
|
89
92
|
} catch (error) {
|
|
93
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
90
94
|
const wasAuthenticated = statusRef.current === "authenticated";
|
|
91
95
|
if (isSessionExpiredError(error)) {
|
|
92
96
|
if (!isInitial && wasAuthenticated) {
|
|
@@ -139,11 +143,13 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
139
143
|
tenantId
|
|
140
144
|
});
|
|
141
145
|
if ("mfaRequired" in result) {
|
|
146
|
+
sessionGenerationRef.current = {};
|
|
142
147
|
syncedDispatch({
|
|
143
148
|
type: "CLEAR_SESSION"
|
|
144
149
|
});
|
|
145
150
|
return result;
|
|
146
151
|
}
|
|
152
|
+
sessionGenerationRef.current = {};
|
|
147
153
|
syncedDispatch({
|
|
148
154
|
type: "SET_USER",
|
|
149
155
|
payload: {
|
|
@@ -167,6 +173,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
167
173
|
});
|
|
168
174
|
try {
|
|
169
175
|
const result = await clientRef.current.register(data);
|
|
176
|
+
sessionGenerationRef.current = {};
|
|
170
177
|
syncedDispatch({
|
|
171
178
|
type: "SET_USER",
|
|
172
179
|
payload: {
|
|
@@ -188,6 +195,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
188
195
|
try {
|
|
189
196
|
await clientRef.current.logout();
|
|
190
197
|
} finally {
|
|
198
|
+
sessionGenerationRef.current = {};
|
|
191
199
|
syncedDispatch({
|
|
192
200
|
type: "CLEAR_SESSION"
|
|
193
201
|
});
|