@bymax-one/nest-auth 1.0.10 → 1.1.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 +387 -1
- package/README.md +274 -108
- package/dist/client/index.cjs +41 -4
- package/dist/client/index.mjs +41 -4
- package/dist/nextjs/index.cjs +152 -51
- package/dist/nextjs/index.d.cts +149 -55
- package/dist/nextjs/index.d.ts +149 -55
- package/dist/nextjs/index.mjs +152 -51
- package/dist/react/index.cjs +77 -89
- package/dist/react/index.mjs +77 -89
- package/dist/server/index.cjs +5951 -1655
- package/dist/server/index.d.cts +2818 -188
- package/dist/server/index.d.ts +2818 -188
- package/dist/server/index.mjs +5933 -1644
- package/dist/shared/index.cjs +60 -9
- package/dist/shared/index.d.cts +126 -18
- package/dist/shared/index.d.ts +126 -18
- package/dist/shared/index.mjs +60 -9
- package/package.json +133 -45
package/dist/react/index.mjs
CHANGED
|
@@ -76,42 +76,38 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
}, []);
|
|
79
|
-
const revalidate = useCallback(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
console.warn("[nest-auth] onSessionExpired callback threw:", callbackError);
|
|
98
|
-
}
|
|
79
|
+
const revalidate = useCallback(async (isInitial) => {
|
|
80
|
+
try {
|
|
81
|
+
const user = await clientRef.current.getMe();
|
|
82
|
+
syncedDispatch({
|
|
83
|
+
type: "SET_USER",
|
|
84
|
+
payload: {
|
|
85
|
+
user,
|
|
86
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const wasAuthenticated = statusRef.current === "authenticated";
|
|
91
|
+
if (isSessionExpiredError(error)) {
|
|
92
|
+
if (!isInitial && wasAuthenticated) {
|
|
93
|
+
try {
|
|
94
|
+
onSessionExpiredRef.current?.();
|
|
95
|
+
} catch (callbackError) {
|
|
96
|
+
console.warn("[nest-auth] onSessionExpired callback threw:", callbackError);
|
|
99
97
|
}
|
|
100
|
-
syncedDispatch({
|
|
101
|
-
type: "CLEAR_SESSION"
|
|
102
|
-
});
|
|
103
|
-
return;
|
|
104
98
|
}
|
|
105
99
|
syncedDispatch({
|
|
106
|
-
type: "
|
|
100
|
+
type: "CLEAR_SESSION"
|
|
107
101
|
});
|
|
102
|
+
return;
|
|
108
103
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
syncedDispatch({
|
|
105
|
+
type: "SET_ERROR"
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, [
|
|
109
|
+
syncedDispatch
|
|
110
|
+
]);
|
|
115
111
|
useEffect(() => {
|
|
116
112
|
void revalidate(true);
|
|
117
113
|
}, [
|
|
@@ -131,71 +127,63 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
131
127
|
revalidate,
|
|
132
128
|
revalidateInterval
|
|
133
129
|
]);
|
|
134
|
-
const login = useCallback(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
const login = useCallback(async (email, password, options) => {
|
|
131
|
+
const tenantId = options?.tenantId ?? DEFAULT_TENANT_ID;
|
|
132
|
+
syncedDispatch({
|
|
133
|
+
type: "SET_LOADING"
|
|
134
|
+
});
|
|
135
|
+
try {
|
|
136
|
+
const result = await clientRef.current.login({
|
|
137
|
+
email,
|
|
138
|
+
password,
|
|
139
|
+
tenantId
|
|
139
140
|
});
|
|
140
|
-
|
|
141
|
-
const result = await clientRef.current.login({
|
|
142
|
-
email,
|
|
143
|
-
password,
|
|
144
|
-
tenantId
|
|
145
|
-
});
|
|
146
|
-
if ("mfaRequired" in result) {
|
|
147
|
-
syncedDispatch({
|
|
148
|
-
type: "CLEAR_SESSION"
|
|
149
|
-
});
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
141
|
+
if ("mfaRequired" in result) {
|
|
152
142
|
syncedDispatch({
|
|
153
|
-
type: "
|
|
154
|
-
payload: {
|
|
155
|
-
user: result.user,
|
|
156
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
157
|
-
}
|
|
143
|
+
type: "CLEAR_SESSION"
|
|
158
144
|
});
|
|
159
145
|
return result;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
syncedDispatch({
|
|
162
|
-
type: "SET_ERROR"
|
|
163
|
-
});
|
|
164
|
-
throw error;
|
|
165
146
|
}
|
|
166
|
-
},
|
|
167
|
-
// Stryker disable next-line ArrayDeclaration: deps hold only the stable `syncedDispatch`, so emptying the array does not change memoization
|
|
168
|
-
[
|
|
169
|
-
syncedDispatch
|
|
170
|
-
]
|
|
171
|
-
);
|
|
172
|
-
const register = useCallback(
|
|
173
|
-
async (data) => {
|
|
174
147
|
syncedDispatch({
|
|
175
|
-
type: "
|
|
148
|
+
type: "SET_USER",
|
|
149
|
+
payload: {
|
|
150
|
+
user: result.user,
|
|
151
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
152
|
+
}
|
|
176
153
|
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
154
|
+
return result;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
syncedDispatch({
|
|
157
|
+
type: "SET_ERROR"
|
|
158
|
+
});
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}, [
|
|
162
|
+
syncedDispatch
|
|
163
|
+
]);
|
|
164
|
+
const register = useCallback(async (data) => {
|
|
165
|
+
syncedDispatch({
|
|
166
|
+
type: "SET_LOADING"
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
const result = await clientRef.current.register(data);
|
|
170
|
+
syncedDispatch({
|
|
171
|
+
type: "SET_USER",
|
|
172
|
+
payload: {
|
|
173
|
+
user: result.user,
|
|
174
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return result;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
syncedDispatch({
|
|
180
|
+
type: "SET_ERROR"
|
|
181
|
+
});
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}, [
|
|
185
|
+
syncedDispatch
|
|
186
|
+
]);
|
|
199
187
|
const logout = useCallback(async () => {
|
|
200
188
|
try {
|
|
201
189
|
await clientRef.current.logout();
|