-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathuseConfirmPasswordReset.ts
More file actions
38 lines (33 loc) · 1021 Bytes
/
useConfirmPasswordReset.ts
File metadata and controls
38 lines (33 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
ActionCodeSettings,
Auth,
AuthError,
confirmPasswordReset as fbConfirmPasswordReset,
} from 'firebase/auth';
import { useCallback, useState } from 'react';
export type ConfirmPasswordResetHook = [
(email: string, newPassword: string) => Promise<boolean>,
boolean,
AuthError | Error | undefined
];
export default (auth: Auth): ConfirmPasswordResetHook => {
const [error, setError] = useState<AuthError>();
const [loading, setLoading] = useState<boolean>(false);
const confirmPasswordReset = useCallback(
async (oobCode: string, newPassword:string) => {
setLoading(true);
setError(undefined);
try {
await fbConfirmPasswordReset(auth, oobCode, newPassword);
return true;
} catch (err) {
setError(err as AuthError);
return false;
} finally {
setLoading(false);
}
},
[auth]
);
return [confirmPasswordReset, loading, error];
};