forked from CSFrequency/react-firebase-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSignOut.ts
More file actions
29 lines (25 loc) · 677 Bytes
/
useSignOut.ts
File metadata and controls
29 lines (25 loc) · 677 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
import { Auth, AuthError } from 'firebase/auth';
import { useCallback, useState } from 'react';
export type SignOutHook = [
() => Promise<boolean>,
boolean,
AuthError | Error | undefined
];
export default (auth: Auth): SignOutHook => {
const [error, setError] = useState<AuthError>();
const [loading, setLoading] = useState<boolean>(false);
const signOut = useCallback(async () => {
setLoading(true);
setError(undefined);
try {
await auth.signOut();
return true;
} catch (err) {
setError(err as AuthError);
return false;
} finally {
setLoading(false);
}
}, [auth]);
return [signOut, loading, error];
};