@fonderie/react-native-auth 0.4.0 → 0.6.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/dist/index.cjs +341 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -3
- package/dist/index.d.ts +57 -3
- package/dist/index.js +330 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,29 +30,122 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
FonderieApiError: () =>
|
|
34
|
-
|
|
33
|
+
FonderieApiError: () => import_client12.FonderieApiError,
|
|
34
|
+
TOKEN_KEY: () => TOKEN_KEY,
|
|
35
|
+
clearToken: () => clearToken,
|
|
36
|
+
isMfaRequired: () => import_client12.isMfaRequired,
|
|
37
|
+
persistToken: () => persistToken,
|
|
38
|
+
readToken: () => readToken,
|
|
39
|
+
useAccountData: () => useAccountData,
|
|
40
|
+
useChangePassword: () => useChangePassword,
|
|
35
41
|
useForgotPassword: () => useForgotPassword,
|
|
36
42
|
useLogin: () => useLogin,
|
|
37
43
|
useLogout: () => useLogout,
|
|
44
|
+
useMfaLogin: () => useMfaLogin,
|
|
45
|
+
useMfaSetup: () => useMfaSetup,
|
|
46
|
+
useProfile: () => useProfile,
|
|
38
47
|
useRegister: () => useRegister,
|
|
39
48
|
useResetPassword: () => useResetPassword,
|
|
40
49
|
useSession: () => useSession,
|
|
41
50
|
useVerifyEmail: () => useVerifyEmail
|
|
42
51
|
});
|
|
43
52
|
module.exports = __toCommonJS(index_exports);
|
|
44
|
-
var
|
|
53
|
+
var import_client12 = require("@fonderie/client");
|
|
45
54
|
|
|
46
|
-
// src/hooks/
|
|
55
|
+
// src/hooks/useAccountData.ts
|
|
47
56
|
var import_client = require("@fonderie/client");
|
|
48
57
|
var import_react = require("@fonderie/react");
|
|
49
58
|
var import_react2 = require("react");
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
|
|
60
|
+
// src/storage.ts
|
|
61
|
+
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
|
|
62
|
+
var TOKEN_KEY = "fonderie_access_token";
|
|
63
|
+
function persistToken(token) {
|
|
64
|
+
return import_async_storage.default.setItem(TOKEN_KEY, token);
|
|
65
|
+
}
|
|
66
|
+
function clearToken() {
|
|
67
|
+
return import_async_storage.default.removeItem(TOKEN_KEY);
|
|
68
|
+
}
|
|
69
|
+
function readToken() {
|
|
70
|
+
return import_async_storage.default.getItem(TOKEN_KEY);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/hooks/useAccountData.ts
|
|
74
|
+
function useAccountData(client) {
|
|
75
|
+
const auth = (0, import_react.useFonderieSubClient)(client, (c) => c.auth, "useAccountData");
|
|
52
76
|
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
53
77
|
const [error, setError] = (0, import_react2.useState)(null);
|
|
54
|
-
const
|
|
55
|
-
|
|
78
|
+
const run = (0, import_react2.useCallback)(async (op) => {
|
|
79
|
+
setIsLoading(true);
|
|
80
|
+
setError(null);
|
|
81
|
+
try {
|
|
82
|
+
return await op();
|
|
83
|
+
} catch (err) {
|
|
84
|
+
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
85
|
+
setError(apiError);
|
|
86
|
+
throw apiError;
|
|
87
|
+
} finally {
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
}
|
|
90
|
+
}, []);
|
|
91
|
+
const exportData = (0, import_react2.useCallback)(
|
|
92
|
+
() => run(async () => {
|
|
93
|
+
const { result } = await auth.exportData();
|
|
94
|
+
return result;
|
|
95
|
+
}),
|
|
96
|
+
[auth, run]
|
|
97
|
+
);
|
|
98
|
+
const deleteUser = (0, import_react2.useCallback)(
|
|
99
|
+
() => run(async () => {
|
|
100
|
+
await auth.deleteUser();
|
|
101
|
+
auth.setAccessToken(void 0);
|
|
102
|
+
await clearToken();
|
|
103
|
+
}),
|
|
104
|
+
[auth, run]
|
|
105
|
+
);
|
|
106
|
+
return { exportData, deleteUser, isLoading, error };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/hooks/useChangePassword.ts
|
|
110
|
+
var import_client2 = require("@fonderie/client");
|
|
111
|
+
var import_react3 = require("@fonderie/react");
|
|
112
|
+
var import_react4 = require("react");
|
|
113
|
+
function useChangePassword(client) {
|
|
114
|
+
const auth = (0, import_react3.useFonderieSubClient)(client, (c) => c.auth, "useChangePassword");
|
|
115
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
116
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
117
|
+
const [done, setDone] = (0, import_react4.useState)(false);
|
|
118
|
+
const changePassword = (0, import_react4.useCallback)(
|
|
119
|
+
async (input) => {
|
|
120
|
+
setIsLoading(true);
|
|
121
|
+
setError(null);
|
|
122
|
+
setDone(false);
|
|
123
|
+
try {
|
|
124
|
+
await auth.changePassword(input);
|
|
125
|
+
setDone(true);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
const apiError = err instanceof import_client2.FonderieApiError ? err : new import_client2.FonderieApiError("unknown", String(err), 0);
|
|
128
|
+
setError(apiError);
|
|
129
|
+
throw apiError;
|
|
130
|
+
} finally {
|
|
131
|
+
setIsLoading(false);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
[auth]
|
|
135
|
+
);
|
|
136
|
+
return { changePassword, isLoading, error, done };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/hooks/useForgotPassword.ts
|
|
140
|
+
var import_client3 = require("@fonderie/client");
|
|
141
|
+
var import_react5 = require("@fonderie/react");
|
|
142
|
+
var import_react6 = require("react");
|
|
143
|
+
function useForgotPassword(client) {
|
|
144
|
+
const auth = (0, import_react5.useFonderieSubClient)(client, (c) => c.auth, "useForgotPassword");
|
|
145
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
146
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
147
|
+
const [sent, setSent] = (0, import_react6.useState)(false);
|
|
148
|
+
const forgotPassword = (0, import_react6.useCallback)(
|
|
56
149
|
async (email) => {
|
|
57
150
|
setIsLoading(true);
|
|
58
151
|
setError(null);
|
|
@@ -60,7 +153,7 @@ function useForgotPassword(client) {
|
|
|
60
153
|
await auth.forgotPassword(email);
|
|
61
154
|
setSent(true);
|
|
62
155
|
} catch (err) {
|
|
63
|
-
const apiError = err instanceof
|
|
156
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
64
157
|
setError(apiError);
|
|
65
158
|
throw apiError;
|
|
66
159
|
} finally {
|
|
@@ -73,38 +166,23 @@ function useForgotPassword(client) {
|
|
|
73
166
|
}
|
|
74
167
|
|
|
75
168
|
// src/hooks/useLogin.ts
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
// src/storage.ts
|
|
81
|
-
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
|
|
82
|
-
var TOKEN_KEY = "fonderie_access_token";
|
|
83
|
-
function persistToken(token) {
|
|
84
|
-
return import_async_storage.default.setItem(TOKEN_KEY, token);
|
|
85
|
-
}
|
|
86
|
-
function clearToken() {
|
|
87
|
-
return import_async_storage.default.removeItem(TOKEN_KEY);
|
|
88
|
-
}
|
|
89
|
-
function readToken() {
|
|
90
|
-
return import_async_storage.default.getItem(TOKEN_KEY);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/hooks/useLogin.ts
|
|
169
|
+
var import_client4 = require("@fonderie/client");
|
|
170
|
+
var import_react7 = require("@fonderie/react");
|
|
171
|
+
var import_react8 = require("react");
|
|
94
172
|
function useLogin(client) {
|
|
95
|
-
const auth = (0,
|
|
96
|
-
const [isLoading, setIsLoading] = (0,
|
|
97
|
-
const [error, setError] = (0,
|
|
98
|
-
const [data, setData] = (0,
|
|
99
|
-
const [mfaPending, setMfaPending] = (0,
|
|
100
|
-
const login = (0,
|
|
173
|
+
const auth = (0, import_react7.useFonderieSubClient)(client, (c) => c.auth, "useLogin");
|
|
174
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
175
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
176
|
+
const [data, setData] = (0, import_react8.useState)(null);
|
|
177
|
+
const [mfaPending, setMfaPending] = (0, import_react8.useState)(null);
|
|
178
|
+
const login = (0, import_react8.useCallback)(
|
|
101
179
|
async (input) => {
|
|
102
180
|
setIsLoading(true);
|
|
103
181
|
setError(null);
|
|
104
182
|
setMfaPending(null);
|
|
105
183
|
try {
|
|
106
184
|
const { result } = await auth.login(input);
|
|
107
|
-
if ((0,
|
|
185
|
+
if ((0, import_client4.isMfaRequired)(result)) {
|
|
108
186
|
setMfaPending(result);
|
|
109
187
|
return result;
|
|
110
188
|
}
|
|
@@ -113,7 +191,7 @@ function useLogin(client) {
|
|
|
113
191
|
setData(result);
|
|
114
192
|
return result;
|
|
115
193
|
} catch (err) {
|
|
116
|
-
const apiError = err instanceof
|
|
194
|
+
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
117
195
|
setError(apiError);
|
|
118
196
|
throw apiError;
|
|
119
197
|
} finally {
|
|
@@ -125,21 +203,179 @@ function useLogin(client) {
|
|
|
125
203
|
return { login, isLoading, error, data, mfaPending };
|
|
126
204
|
}
|
|
127
205
|
|
|
206
|
+
// src/hooks/useMfaLogin.ts
|
|
207
|
+
var import_client5 = require("@fonderie/client");
|
|
208
|
+
var import_react9 = require("@fonderie/react");
|
|
209
|
+
var import_react10 = require("react");
|
|
210
|
+
function useMfaLogin(client) {
|
|
211
|
+
const auth = (0, import_react9.useFonderieSubClient)(client, (c) => c.auth, "useMfaLogin");
|
|
212
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
213
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
214
|
+
const [data, setData] = (0, import_react10.useState)(null);
|
|
215
|
+
const verifyLogin = (0, import_react10.useCallback)(
|
|
216
|
+
async (mfaToken, code) => {
|
|
217
|
+
setIsLoading(true);
|
|
218
|
+
setError(null);
|
|
219
|
+
try {
|
|
220
|
+
const { result } = await auth.mfa.verifyLogin(mfaToken, code);
|
|
221
|
+
auth.setAccessToken(result.tokens.access);
|
|
222
|
+
await persistToken(result.tokens.access);
|
|
223
|
+
setData(result);
|
|
224
|
+
return result;
|
|
225
|
+
} catch (err) {
|
|
226
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
227
|
+
setError(apiError);
|
|
228
|
+
throw apiError;
|
|
229
|
+
} finally {
|
|
230
|
+
setIsLoading(false);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
[auth]
|
|
234
|
+
);
|
|
235
|
+
return { verifyLogin, isLoading, error, data };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/hooks/useMfaSetup.ts
|
|
239
|
+
var import_client6 = require("@fonderie/client");
|
|
240
|
+
var import_react11 = require("@fonderie/react");
|
|
241
|
+
var import_react12 = require("react");
|
|
242
|
+
function useMfaSetup(client) {
|
|
243
|
+
const auth = (0, import_react11.useFonderieSubClient)(client, (c) => c.auth, "useMfaSetup");
|
|
244
|
+
const [setupData, setSetupData] = (0, import_react12.useState)(null);
|
|
245
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
246
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
247
|
+
const run = (0, import_react12.useCallback)(async (op) => {
|
|
248
|
+
setIsLoading(true);
|
|
249
|
+
setError(null);
|
|
250
|
+
try {
|
|
251
|
+
return await op();
|
|
252
|
+
} catch (err) {
|
|
253
|
+
const apiError = err instanceof import_client6.FonderieApiError ? err : new import_client6.FonderieApiError("unknown", String(err), 0);
|
|
254
|
+
setError(apiError);
|
|
255
|
+
throw apiError;
|
|
256
|
+
} finally {
|
|
257
|
+
setIsLoading(false);
|
|
258
|
+
}
|
|
259
|
+
}, []);
|
|
260
|
+
const setup = (0, import_react12.useCallback)(
|
|
261
|
+
() => run(async () => {
|
|
262
|
+
const { result } = await auth.mfa.setup();
|
|
263
|
+
setSetupData(result);
|
|
264
|
+
return result;
|
|
265
|
+
}),
|
|
266
|
+
[auth, run]
|
|
267
|
+
);
|
|
268
|
+
const verify = (0, import_react12.useCallback)(
|
|
269
|
+
(code) => run(async () => {
|
|
270
|
+
const { result } = await auth.mfa.verify(code);
|
|
271
|
+
auth.setAccessToken(result.tokens.access);
|
|
272
|
+
await persistToken(result.tokens.access);
|
|
273
|
+
return result;
|
|
274
|
+
}),
|
|
275
|
+
[auth, run]
|
|
276
|
+
);
|
|
277
|
+
const disable = (0, import_react12.useCallback)(
|
|
278
|
+
(code) => run(async () => {
|
|
279
|
+
await auth.mfa.disable(code);
|
|
280
|
+
}),
|
|
281
|
+
[auth, run]
|
|
282
|
+
);
|
|
283
|
+
const regenerateBackupCodes = (0, import_react12.useCallback)(
|
|
284
|
+
(code) => run(async () => {
|
|
285
|
+
const { result } = await auth.mfa.regenerateBackupCodes(code);
|
|
286
|
+
return result.backupCodes;
|
|
287
|
+
}),
|
|
288
|
+
[auth, run]
|
|
289
|
+
);
|
|
290
|
+
return { setup, setupData, verify, disable, regenerateBackupCodes, isLoading, error };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/hooks/useProfile.ts
|
|
294
|
+
var import_client7 = require("@fonderie/client");
|
|
295
|
+
var import_react13 = require("@fonderie/react");
|
|
296
|
+
var import_react14 = require("react");
|
|
297
|
+
function useProfile(client) {
|
|
298
|
+
const auth = (0, import_react13.useFonderieSubClient)(client, (c) => c.auth, "useProfile");
|
|
299
|
+
const [user, setUser] = (0, import_react14.useState)(null);
|
|
300
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(true);
|
|
301
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
302
|
+
const refresh = (0, import_react14.useCallback)(async () => {
|
|
303
|
+
setIsLoading(true);
|
|
304
|
+
setError(null);
|
|
305
|
+
try {
|
|
306
|
+
const { result } = await auth.getUser();
|
|
307
|
+
setUser(result.user);
|
|
308
|
+
} catch (err) {
|
|
309
|
+
const apiError = err instanceof import_client7.FonderieApiError ? err : new import_client7.FonderieApiError("unknown", String(err), 0);
|
|
310
|
+
setError(apiError);
|
|
311
|
+
} finally {
|
|
312
|
+
setIsLoading(false);
|
|
313
|
+
}
|
|
314
|
+
}, [auth]);
|
|
315
|
+
const mutate = (0, import_react14.useCallback)(
|
|
316
|
+
async (op) => {
|
|
317
|
+
setError(null);
|
|
318
|
+
try {
|
|
319
|
+
return await op();
|
|
320
|
+
} catch (err) {
|
|
321
|
+
const apiError = err instanceof import_client7.FonderieApiError ? err : new import_client7.FonderieApiError("unknown", String(err), 0);
|
|
322
|
+
setError(apiError);
|
|
323
|
+
throw apiError;
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
[]
|
|
327
|
+
);
|
|
328
|
+
const updateProfile = (0, import_react14.useCallback)(
|
|
329
|
+
(input) => mutate(async () => {
|
|
330
|
+
const { result } = await auth.updateProfile(input);
|
|
331
|
+
setUser(result.user);
|
|
332
|
+
return result.user;
|
|
333
|
+
}),
|
|
334
|
+
[auth, mutate]
|
|
335
|
+
);
|
|
336
|
+
const updatePreferences = (0, import_react14.useCallback)(
|
|
337
|
+
(input) => mutate(async () => {
|
|
338
|
+
const { result } = await auth.updatePreferences(input);
|
|
339
|
+
setUser(result.user);
|
|
340
|
+
return result.user;
|
|
341
|
+
}),
|
|
342
|
+
[auth, mutate]
|
|
343
|
+
);
|
|
344
|
+
const updateEmail = (0, import_react14.useCallback)(
|
|
345
|
+
(email) => mutate(async () => {
|
|
346
|
+
await auth.updateEmail(email);
|
|
347
|
+
await refresh();
|
|
348
|
+
}),
|
|
349
|
+
[auth, mutate, refresh]
|
|
350
|
+
);
|
|
351
|
+
const updatePhone = (0, import_react14.useCallback)(
|
|
352
|
+
(phone) => mutate(async () => {
|
|
353
|
+
await auth.updatePhone(phone);
|
|
354
|
+
await refresh();
|
|
355
|
+
}),
|
|
356
|
+
[auth, mutate, refresh]
|
|
357
|
+
);
|
|
358
|
+
(0, import_react14.useEffect)(() => {
|
|
359
|
+
void refresh();
|
|
360
|
+
}, [refresh]);
|
|
361
|
+
return { user, refresh, updateProfile, updatePreferences, updateEmail, updatePhone, isLoading, error };
|
|
362
|
+
}
|
|
363
|
+
|
|
128
364
|
// src/hooks/useLogout.ts
|
|
129
|
-
var
|
|
130
|
-
var
|
|
131
|
-
var
|
|
365
|
+
var import_client8 = require("@fonderie/client");
|
|
366
|
+
var import_react15 = require("@fonderie/react");
|
|
367
|
+
var import_react16 = require("react");
|
|
132
368
|
function useLogout(client) {
|
|
133
|
-
const auth = (0,
|
|
134
|
-
const [isLoading, setIsLoading] = (0,
|
|
135
|
-
const [error, setError] = (0,
|
|
136
|
-
const logout = (0,
|
|
369
|
+
const auth = (0, import_react15.useFonderieSubClient)(client, (c) => c.auth, "useLogout");
|
|
370
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
|
|
371
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
372
|
+
const logout = (0, import_react16.useCallback)(async (refreshToken) => {
|
|
137
373
|
setIsLoading(true);
|
|
138
374
|
setError(null);
|
|
139
375
|
try {
|
|
140
376
|
await auth.logout(refreshToken);
|
|
141
377
|
} catch (err) {
|
|
142
|
-
const apiError = err instanceof
|
|
378
|
+
const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
|
|
143
379
|
setError(apiError);
|
|
144
380
|
} finally {
|
|
145
381
|
auth.setAccessToken(void 0);
|
|
@@ -151,15 +387,15 @@ function useLogout(client) {
|
|
|
151
387
|
}
|
|
152
388
|
|
|
153
389
|
// src/hooks/useRegister.ts
|
|
154
|
-
var
|
|
155
|
-
var
|
|
156
|
-
var
|
|
390
|
+
var import_client9 = require("@fonderie/client");
|
|
391
|
+
var import_react17 = require("@fonderie/react");
|
|
392
|
+
var import_react18 = require("react");
|
|
157
393
|
function useRegister(client) {
|
|
158
|
-
const auth = (0,
|
|
159
|
-
const [isLoading, setIsLoading] = (0,
|
|
160
|
-
const [error, setError] = (0,
|
|
161
|
-
const [data, setData] = (0,
|
|
162
|
-
const register = (0,
|
|
394
|
+
const auth = (0, import_react17.useFonderieSubClient)(client, (c) => c.auth, "useRegister");
|
|
395
|
+
const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
|
|
396
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
397
|
+
const [data, setData] = (0, import_react18.useState)(null);
|
|
398
|
+
const register = (0, import_react18.useCallback)(
|
|
163
399
|
async (input) => {
|
|
164
400
|
setIsLoading(true);
|
|
165
401
|
setError(null);
|
|
@@ -170,7 +406,7 @@ function useRegister(client) {
|
|
|
170
406
|
setData(result);
|
|
171
407
|
return result;
|
|
172
408
|
} catch (err) {
|
|
173
|
-
const apiError = err instanceof
|
|
409
|
+
const apiError = err instanceof import_client9.FonderieApiError ? err : new import_client9.FonderieApiError("unknown", String(err), 0);
|
|
174
410
|
setError(apiError);
|
|
175
411
|
throw apiError;
|
|
176
412
|
} finally {
|
|
@@ -183,15 +419,15 @@ function useRegister(client) {
|
|
|
183
419
|
}
|
|
184
420
|
|
|
185
421
|
// src/hooks/useResetPassword.ts
|
|
186
|
-
var
|
|
187
|
-
var
|
|
188
|
-
var
|
|
422
|
+
var import_client10 = require("@fonderie/client");
|
|
423
|
+
var import_react19 = require("@fonderie/react");
|
|
424
|
+
var import_react20 = require("react");
|
|
189
425
|
function useResetPassword(client) {
|
|
190
|
-
const auth = (0,
|
|
191
|
-
const [isLoading, setIsLoading] = (0,
|
|
192
|
-
const [error, setError] = (0,
|
|
193
|
-
const [done, setDone] = (0,
|
|
194
|
-
const resetPassword = (0,
|
|
426
|
+
const auth = (0, import_react19.useFonderieSubClient)(client, (c) => c.auth, "useResetPassword");
|
|
427
|
+
const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
|
|
428
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
429
|
+
const [done, setDone] = (0, import_react20.useState)(false);
|
|
430
|
+
const resetPassword = (0, import_react20.useCallback)(
|
|
195
431
|
async (input) => {
|
|
196
432
|
setIsLoading(true);
|
|
197
433
|
setError(null);
|
|
@@ -199,7 +435,7 @@ function useResetPassword(client) {
|
|
|
199
435
|
await auth.resetPassword(input);
|
|
200
436
|
setDone(true);
|
|
201
437
|
} catch (err) {
|
|
202
|
-
const apiError = err instanceof
|
|
438
|
+
const apiError = err instanceof import_client10.FonderieApiError ? err : new import_client10.FonderieApiError("unknown", String(err), 0);
|
|
203
439
|
setError(apiError);
|
|
204
440
|
throw apiError;
|
|
205
441
|
} finally {
|
|
@@ -212,14 +448,14 @@ function useResetPassword(client) {
|
|
|
212
448
|
}
|
|
213
449
|
|
|
214
450
|
// src/hooks/useSession.ts
|
|
215
|
-
var
|
|
216
|
-
var
|
|
451
|
+
var import_react21 = require("@fonderie/react");
|
|
452
|
+
var import_react22 = require("react");
|
|
217
453
|
function useSession(client) {
|
|
218
|
-
const auth = (0,
|
|
219
|
-
const [user, setUser] = (0,
|
|
220
|
-
const [isLoading, setIsLoading] = (0,
|
|
221
|
-
const [isAuthenticated, setIsAuthenticated] = (0,
|
|
222
|
-
const refresh = (0,
|
|
454
|
+
const auth = (0, import_react21.useFonderieSubClient)(client, (c) => c.auth, "useSession");
|
|
455
|
+
const [user, setUser] = (0, import_react22.useState)(null);
|
|
456
|
+
const [isLoading, setIsLoading] = (0, import_react22.useState)(true);
|
|
457
|
+
const [isAuthenticated, setIsAuthenticated] = (0, import_react22.useState)(false);
|
|
458
|
+
const refresh = (0, import_react22.useCallback)(async () => {
|
|
223
459
|
setIsLoading(true);
|
|
224
460
|
try {
|
|
225
461
|
const { result } = await auth.getUser();
|
|
@@ -234,7 +470,7 @@ function useSession(client) {
|
|
|
234
470
|
setIsLoading(false);
|
|
235
471
|
}
|
|
236
472
|
}, [auth]);
|
|
237
|
-
const logout = (0,
|
|
473
|
+
const logout = (0, import_react22.useCallback)(async (refreshToken) => {
|
|
238
474
|
try {
|
|
239
475
|
await auth.logout(refreshToken);
|
|
240
476
|
} catch {
|
|
@@ -244,7 +480,7 @@ function useSession(client) {
|
|
|
244
480
|
setUser(null);
|
|
245
481
|
setIsAuthenticated(false);
|
|
246
482
|
}, [auth]);
|
|
247
|
-
(0,
|
|
483
|
+
(0, import_react22.useEffect)(() => {
|
|
248
484
|
readToken().then((token) => {
|
|
249
485
|
if (token) auth.setAccessToken(token);
|
|
250
486
|
void refresh();
|
|
@@ -254,15 +490,31 @@ function useSession(client) {
|
|
|
254
490
|
}
|
|
255
491
|
|
|
256
492
|
// src/hooks/useVerifyEmail.ts
|
|
257
|
-
var
|
|
258
|
-
var
|
|
259
|
-
var
|
|
493
|
+
var import_client11 = require("@fonderie/client");
|
|
494
|
+
var import_react23 = require("@fonderie/react");
|
|
495
|
+
var import_react24 = require("react");
|
|
260
496
|
function useVerifyEmail(client) {
|
|
261
|
-
const auth = (0,
|
|
262
|
-
const [isLoading, setIsLoading] = (0,
|
|
263
|
-
const [error, setError] = (0,
|
|
264
|
-
const [data, setData] = (0,
|
|
265
|
-
const
|
|
497
|
+
const auth = (0, import_react23.useFonderieSubClient)(client, (c) => c.auth, "useVerifyEmail");
|
|
498
|
+
const [isLoading, setIsLoading] = (0, import_react24.useState)(false);
|
|
499
|
+
const [error, setError] = (0, import_react24.useState)(null);
|
|
500
|
+
const [data, setData] = (0, import_react24.useState)(null);
|
|
501
|
+
const [resent, setResent] = (0, import_react24.useState)(false);
|
|
502
|
+
const resend = (0, import_react24.useCallback)(async () => {
|
|
503
|
+
setIsLoading(true);
|
|
504
|
+
setError(null);
|
|
505
|
+
setResent(false);
|
|
506
|
+
try {
|
|
507
|
+
await auth.sendVerificationEmail();
|
|
508
|
+
setResent(true);
|
|
509
|
+
} catch (err) {
|
|
510
|
+
const apiError = err instanceof import_client11.FonderieApiError ? err : new import_client11.FonderieApiError("unknown", String(err), 0);
|
|
511
|
+
setError(apiError);
|
|
512
|
+
throw apiError;
|
|
513
|
+
} finally {
|
|
514
|
+
setIsLoading(false);
|
|
515
|
+
}
|
|
516
|
+
}, [auth]);
|
|
517
|
+
const verifyEmail = (0, import_react24.useCallback)(
|
|
266
518
|
async (pin) => {
|
|
267
519
|
setIsLoading(true);
|
|
268
520
|
setError(null);
|
|
@@ -271,7 +523,7 @@ function useVerifyEmail(client) {
|
|
|
271
523
|
setData(result);
|
|
272
524
|
return result;
|
|
273
525
|
} catch (err) {
|
|
274
|
-
const apiError = err instanceof
|
|
526
|
+
const apiError = err instanceof import_client11.FonderieApiError ? err : new import_client11.FonderieApiError("unknown", String(err), 0);
|
|
275
527
|
setError(apiError);
|
|
276
528
|
throw apiError;
|
|
277
529
|
} finally {
|
|
@@ -280,15 +532,24 @@ function useVerifyEmail(client) {
|
|
|
280
532
|
},
|
|
281
533
|
[auth]
|
|
282
534
|
);
|
|
283
|
-
return { verifyEmail, isLoading, error, data };
|
|
535
|
+
return { verifyEmail, resend, resent, isLoading, error, data };
|
|
284
536
|
}
|
|
285
537
|
// Annotate the CommonJS export names for ESM import in node:
|
|
286
538
|
0 && (module.exports = {
|
|
287
539
|
FonderieApiError,
|
|
540
|
+
TOKEN_KEY,
|
|
541
|
+
clearToken,
|
|
288
542
|
isMfaRequired,
|
|
543
|
+
persistToken,
|
|
544
|
+
readToken,
|
|
545
|
+
useAccountData,
|
|
546
|
+
useChangePassword,
|
|
289
547
|
useForgotPassword,
|
|
290
548
|
useLogin,
|
|
291
549
|
useLogout,
|
|
550
|
+
useMfaLogin,
|
|
551
|
+
useMfaSetup,
|
|
552
|
+
useProfile,
|
|
292
553
|
useRegister,
|
|
293
554
|
useResetPassword,
|
|
294
555
|
useSession,
|