@bymax-one/nest-auth 1.0.11 → 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.
@@ -76,42 +76,38 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
76
76
  return;
77
77
  }
78
78
  }, []);
79
- const revalidate = useCallback(
80
- async (isInitial) => {
81
- try {
82
- const user = await clientRef.current.getMe();
83
- syncedDispatch({
84
- type: "SET_USER",
85
- payload: {
86
- user,
87
- timestamp: /* @__PURE__ */ new Date()
88
- }
89
- });
90
- } catch (error) {
91
- const wasAuthenticated = statusRef.current === "authenticated";
92
- if (isSessionExpiredError(error)) {
93
- if (!isInitial && wasAuthenticated) {
94
- try {
95
- onSessionExpiredRef.current?.();
96
- } catch (callbackError) {
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: "SET_ERROR"
100
+ type: "CLEAR_SESSION"
107
101
  });
102
+ return;
108
103
  }
109
- },
110
- // Stryker disable next-line ArrayDeclaration: deps hold only the stable `syncedDispatch`, so emptying the array does not change effect/memo behavior
111
- [
112
- syncedDispatch
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
- async (email, password, options) => {
136
- const tenantId = options?.tenantId ?? DEFAULT_TENANT_ID;
137
- syncedDispatch({
138
- type: "SET_LOADING"
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
- try {
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: "SET_USER",
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: "SET_LOADING"
148
+ type: "SET_USER",
149
+ payload: {
150
+ user: result.user,
151
+ timestamp: /* @__PURE__ */ new Date()
152
+ }
176
153
  });
177
- try {
178
- const result = await clientRef.current.register(data);
179
- syncedDispatch({
180
- type: "SET_USER",
181
- payload: {
182
- user: result.user,
183
- timestamp: /* @__PURE__ */ new Date()
184
- }
185
- });
186
- return result;
187
- } catch (error) {
188
- syncedDispatch({
189
- type: "SET_ERROR"
190
- });
191
- throw error;
192
- }
193
- },
194
- // Stryker disable next-line ArrayDeclaration: deps hold only the stable `syncedDispatch`, so emptying the array does not change memoization
195
- [
196
- syncedDispatch
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();