@fonderie/react-native-auth 0.5.0 → 0.6.1
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 +308 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +302 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,34 +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: () =>
|
|
33
|
+
FonderieApiError: () => import_client12.FonderieApiError,
|
|
34
34
|
TOKEN_KEY: () => TOKEN_KEY,
|
|
35
35
|
clearToken: () => clearToken,
|
|
36
|
-
isMfaRequired: () =>
|
|
36
|
+
isMfaRequired: () => import_client12.isMfaRequired,
|
|
37
37
|
persistToken: () => persistToken,
|
|
38
38
|
readToken: () => readToken,
|
|
39
|
+
useAccountData: () => useAccountData,
|
|
40
|
+
useChangePassword: () => useChangePassword,
|
|
39
41
|
useForgotPassword: () => useForgotPassword,
|
|
40
42
|
useLogin: () => useLogin,
|
|
41
43
|
useLogout: () => useLogout,
|
|
42
44
|
useMfaLogin: () => useMfaLogin,
|
|
45
|
+
useMfaSetup: () => useMfaSetup,
|
|
46
|
+
useProfile: () => useProfile,
|
|
43
47
|
useRegister: () => useRegister,
|
|
44
48
|
useResetPassword: () => useResetPassword,
|
|
45
49
|
useSession: () => useSession,
|
|
46
50
|
useVerifyEmail: () => useVerifyEmail
|
|
47
51
|
});
|
|
48
52
|
module.exports = __toCommonJS(index_exports);
|
|
49
|
-
var
|
|
53
|
+
var import_client12 = require("@fonderie/client");
|
|
50
54
|
|
|
51
|
-
// src/hooks/
|
|
55
|
+
// src/hooks/useAccountData.ts
|
|
52
56
|
var import_client = require("@fonderie/client");
|
|
53
57
|
var import_react = require("@fonderie/react");
|
|
54
58
|
var import_react2 = require("react");
|
|
55
|
-
|
|
56
|
-
|
|
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");
|
|
57
76
|
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
58
77
|
const [error, setError] = (0, import_react2.useState)(null);
|
|
59
|
-
const
|
|
60
|
-
|
|
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)(
|
|
61
149
|
async (email) => {
|
|
62
150
|
setIsLoading(true);
|
|
63
151
|
setError(null);
|
|
@@ -65,7 +153,7 @@ function useForgotPassword(client) {
|
|
|
65
153
|
await auth.forgotPassword(email);
|
|
66
154
|
setSent(true);
|
|
67
155
|
} catch (err) {
|
|
68
|
-
const apiError = err instanceof
|
|
156
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
69
157
|
setError(apiError);
|
|
70
158
|
throw apiError;
|
|
71
159
|
} finally {
|
|
@@ -78,38 +166,23 @@ function useForgotPassword(client) {
|
|
|
78
166
|
}
|
|
79
167
|
|
|
80
168
|
// src/hooks/useLogin.ts
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
// src/storage.ts
|
|
86
|
-
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
|
|
87
|
-
var TOKEN_KEY = "fonderie_access_token";
|
|
88
|
-
function persistToken(token) {
|
|
89
|
-
return import_async_storage.default.setItem(TOKEN_KEY, token);
|
|
90
|
-
}
|
|
91
|
-
function clearToken() {
|
|
92
|
-
return import_async_storage.default.removeItem(TOKEN_KEY);
|
|
93
|
-
}
|
|
94
|
-
function readToken() {
|
|
95
|
-
return import_async_storage.default.getItem(TOKEN_KEY);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// src/hooks/useLogin.ts
|
|
169
|
+
var import_client4 = require("@fonderie/client");
|
|
170
|
+
var import_react7 = require("@fonderie/react");
|
|
171
|
+
var import_react8 = require("react");
|
|
99
172
|
function useLogin(client) {
|
|
100
|
-
const auth = (0,
|
|
101
|
-
const [isLoading, setIsLoading] = (0,
|
|
102
|
-
const [error, setError] = (0,
|
|
103
|
-
const [data, setData] = (0,
|
|
104
|
-
const [mfaPending, setMfaPending] = (0,
|
|
105
|
-
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)(
|
|
106
179
|
async (input) => {
|
|
107
180
|
setIsLoading(true);
|
|
108
181
|
setError(null);
|
|
109
182
|
setMfaPending(null);
|
|
110
183
|
try {
|
|
111
184
|
const { result } = await auth.login(input);
|
|
112
|
-
if ((0,
|
|
185
|
+
if ((0, import_client4.isMfaRequired)(result)) {
|
|
113
186
|
setMfaPending(result);
|
|
114
187
|
return result;
|
|
115
188
|
}
|
|
@@ -118,7 +191,7 @@ function useLogin(client) {
|
|
|
118
191
|
setData(result);
|
|
119
192
|
return result;
|
|
120
193
|
} catch (err) {
|
|
121
|
-
const apiError = err instanceof
|
|
194
|
+
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
122
195
|
setError(apiError);
|
|
123
196
|
throw apiError;
|
|
124
197
|
} finally {
|
|
@@ -131,15 +204,15 @@ function useLogin(client) {
|
|
|
131
204
|
}
|
|
132
205
|
|
|
133
206
|
// src/hooks/useMfaLogin.ts
|
|
134
|
-
var
|
|
135
|
-
var
|
|
136
|
-
var
|
|
207
|
+
var import_client5 = require("@fonderie/client");
|
|
208
|
+
var import_react9 = require("@fonderie/react");
|
|
209
|
+
var import_react10 = require("react");
|
|
137
210
|
function useMfaLogin(client) {
|
|
138
|
-
const auth = (0,
|
|
139
|
-
const [isLoading, setIsLoading] = (0,
|
|
140
|
-
const [error, setError] = (0,
|
|
141
|
-
const [data, setData] = (0,
|
|
142
|
-
const verifyLogin = (0,
|
|
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)(
|
|
143
216
|
async (mfaToken, code) => {
|
|
144
217
|
setIsLoading(true);
|
|
145
218
|
setError(null);
|
|
@@ -150,7 +223,7 @@ function useMfaLogin(client) {
|
|
|
150
223
|
setData(result);
|
|
151
224
|
return result;
|
|
152
225
|
} catch (err) {
|
|
153
|
-
const apiError = err instanceof
|
|
226
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
154
227
|
setError(apiError);
|
|
155
228
|
throw apiError;
|
|
156
229
|
} finally {
|
|
@@ -162,21 +235,147 @@ function useMfaLogin(client) {
|
|
|
162
235
|
return { verifyLogin, isLoading, error, data };
|
|
163
236
|
}
|
|
164
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
|
+
|
|
165
364
|
// src/hooks/useLogout.ts
|
|
166
|
-
var
|
|
167
|
-
var
|
|
168
|
-
var
|
|
365
|
+
var import_client8 = require("@fonderie/client");
|
|
366
|
+
var import_react15 = require("@fonderie/react");
|
|
367
|
+
var import_react16 = require("react");
|
|
169
368
|
function useLogout(client) {
|
|
170
|
-
const auth = (0,
|
|
171
|
-
const [isLoading, setIsLoading] = (0,
|
|
172
|
-
const [error, setError] = (0,
|
|
173
|
-
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) => {
|
|
174
373
|
setIsLoading(true);
|
|
175
374
|
setError(null);
|
|
176
375
|
try {
|
|
177
376
|
await auth.logout(refreshToken);
|
|
178
377
|
} catch (err) {
|
|
179
|
-
const apiError = err instanceof
|
|
378
|
+
const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
|
|
180
379
|
setError(apiError);
|
|
181
380
|
} finally {
|
|
182
381
|
auth.setAccessToken(void 0);
|
|
@@ -188,15 +387,15 @@ function useLogout(client) {
|
|
|
188
387
|
}
|
|
189
388
|
|
|
190
389
|
// src/hooks/useRegister.ts
|
|
191
|
-
var
|
|
192
|
-
var
|
|
193
|
-
var
|
|
390
|
+
var import_client9 = require("@fonderie/client");
|
|
391
|
+
var import_react17 = require("@fonderie/react");
|
|
392
|
+
var import_react18 = require("react");
|
|
194
393
|
function useRegister(client) {
|
|
195
|
-
const auth = (0,
|
|
196
|
-
const [isLoading, setIsLoading] = (0,
|
|
197
|
-
const [error, setError] = (0,
|
|
198
|
-
const [data, setData] = (0,
|
|
199
|
-
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)(
|
|
200
399
|
async (input) => {
|
|
201
400
|
setIsLoading(true);
|
|
202
401
|
setError(null);
|
|
@@ -207,7 +406,7 @@ function useRegister(client) {
|
|
|
207
406
|
setData(result);
|
|
208
407
|
return result;
|
|
209
408
|
} catch (err) {
|
|
210
|
-
const apiError = err instanceof
|
|
409
|
+
const apiError = err instanceof import_client9.FonderieApiError ? err : new import_client9.FonderieApiError("unknown", String(err), 0);
|
|
211
410
|
setError(apiError);
|
|
212
411
|
throw apiError;
|
|
213
412
|
} finally {
|
|
@@ -220,15 +419,15 @@ function useRegister(client) {
|
|
|
220
419
|
}
|
|
221
420
|
|
|
222
421
|
// src/hooks/useResetPassword.ts
|
|
223
|
-
var
|
|
224
|
-
var
|
|
225
|
-
var
|
|
422
|
+
var import_client10 = require("@fonderie/client");
|
|
423
|
+
var import_react19 = require("@fonderie/react");
|
|
424
|
+
var import_react20 = require("react");
|
|
226
425
|
function useResetPassword(client) {
|
|
227
|
-
const auth = (0,
|
|
228
|
-
const [isLoading, setIsLoading] = (0,
|
|
229
|
-
const [error, setError] = (0,
|
|
230
|
-
const [done, setDone] = (0,
|
|
231
|
-
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)(
|
|
232
431
|
async (input) => {
|
|
233
432
|
setIsLoading(true);
|
|
234
433
|
setError(null);
|
|
@@ -236,7 +435,7 @@ function useResetPassword(client) {
|
|
|
236
435
|
await auth.resetPassword(input);
|
|
237
436
|
setDone(true);
|
|
238
437
|
} catch (err) {
|
|
239
|
-
const apiError = err instanceof
|
|
438
|
+
const apiError = err instanceof import_client10.FonderieApiError ? err : new import_client10.FonderieApiError("unknown", String(err), 0);
|
|
240
439
|
setError(apiError);
|
|
241
440
|
throw apiError;
|
|
242
441
|
} finally {
|
|
@@ -249,14 +448,14 @@ function useResetPassword(client) {
|
|
|
249
448
|
}
|
|
250
449
|
|
|
251
450
|
// src/hooks/useSession.ts
|
|
252
|
-
var
|
|
253
|
-
var
|
|
451
|
+
var import_react21 = require("@fonderie/react");
|
|
452
|
+
var import_react22 = require("react");
|
|
254
453
|
function useSession(client) {
|
|
255
|
-
const auth = (0,
|
|
256
|
-
const [user, setUser] = (0,
|
|
257
|
-
const [isLoading, setIsLoading] = (0,
|
|
258
|
-
const [isAuthenticated, setIsAuthenticated] = (0,
|
|
259
|
-
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 () => {
|
|
260
459
|
setIsLoading(true);
|
|
261
460
|
try {
|
|
262
461
|
const { result } = await auth.getUser();
|
|
@@ -271,7 +470,7 @@ function useSession(client) {
|
|
|
271
470
|
setIsLoading(false);
|
|
272
471
|
}
|
|
273
472
|
}, [auth]);
|
|
274
|
-
const logout = (0,
|
|
473
|
+
const logout = (0, import_react22.useCallback)(async (refreshToken) => {
|
|
275
474
|
try {
|
|
276
475
|
await auth.logout(refreshToken);
|
|
277
476
|
} catch {
|
|
@@ -281,7 +480,7 @@ function useSession(client) {
|
|
|
281
480
|
setUser(null);
|
|
282
481
|
setIsAuthenticated(false);
|
|
283
482
|
}, [auth]);
|
|
284
|
-
(0,
|
|
483
|
+
(0, import_react22.useEffect)(() => {
|
|
285
484
|
readToken().then((token) => {
|
|
286
485
|
if (token) auth.setAccessToken(token);
|
|
287
486
|
void refresh();
|
|
@@ -291,15 +490,31 @@ function useSession(client) {
|
|
|
291
490
|
}
|
|
292
491
|
|
|
293
492
|
// src/hooks/useVerifyEmail.ts
|
|
294
|
-
var
|
|
295
|
-
var
|
|
296
|
-
var
|
|
493
|
+
var import_client11 = require("@fonderie/client");
|
|
494
|
+
var import_react23 = require("@fonderie/react");
|
|
495
|
+
var import_react24 = require("react");
|
|
297
496
|
function useVerifyEmail(client) {
|
|
298
|
-
const auth = (0,
|
|
299
|
-
const [isLoading, setIsLoading] = (0,
|
|
300
|
-
const [error, setError] = (0,
|
|
301
|
-
const [data, setData] = (0,
|
|
302
|
-
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)(
|
|
303
518
|
async (pin) => {
|
|
304
519
|
setIsLoading(true);
|
|
305
520
|
setError(null);
|
|
@@ -308,7 +523,7 @@ function useVerifyEmail(client) {
|
|
|
308
523
|
setData(result);
|
|
309
524
|
return result;
|
|
310
525
|
} catch (err) {
|
|
311
|
-
const apiError = err instanceof
|
|
526
|
+
const apiError = err instanceof import_client11.FonderieApiError ? err : new import_client11.FonderieApiError("unknown", String(err), 0);
|
|
312
527
|
setError(apiError);
|
|
313
528
|
throw apiError;
|
|
314
529
|
} finally {
|
|
@@ -317,7 +532,7 @@ function useVerifyEmail(client) {
|
|
|
317
532
|
},
|
|
318
533
|
[auth]
|
|
319
534
|
);
|
|
320
|
-
return { verifyEmail, isLoading, error, data };
|
|
535
|
+
return { verifyEmail, resend, resent, isLoading, error, data };
|
|
321
536
|
}
|
|
322
537
|
// Annotate the CommonJS export names for ESM import in node:
|
|
323
538
|
0 && (module.exports = {
|
|
@@ -327,10 +542,14 @@ function useVerifyEmail(client) {
|
|
|
327
542
|
isMfaRequired,
|
|
328
543
|
persistToken,
|
|
329
544
|
readToken,
|
|
545
|
+
useAccountData,
|
|
546
|
+
useChangePassword,
|
|
330
547
|
useForgotPassword,
|
|
331
548
|
useLogin,
|
|
332
549
|
useLogout,
|
|
333
550
|
useMfaLogin,
|
|
551
|
+
useMfaSetup,
|
|
552
|
+
useProfile,
|
|
334
553
|
useRegister,
|
|
335
554
|
useResetPassword,
|
|
336
555
|
useSession,
|