Skip to content

Commit 8c5e15d

Browse files
author
nishanth
committed
Changed error type to FirebaseError
1 parent c1a0d20 commit 8c5e15d

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

auth/useLogin.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { useState, useMemo } from 'react';
22
import firebase from 'firebase/app';
3+
import 'firebase/auth';
34
import { AuthHookType } from '../util';
45

5-
export type loginHook = AuthHookType<firebase.auth.UserCredential>;
6+
export type loginHook = AuthHookType<
7+
firebase.auth.UserCredential,
8+
firebase.FirebaseError
9+
>;
610

711
export default (
812
auth: firebase.auth.Auth,
913
email: string,
1014
password: string
1115
): loginHook => {
12-
const [error, setError] = useState<any>(null);
16+
const [error, setError] = useState<firebase.FirebaseError>();
1317
const [
1418
loggedInUser,
1519
setLoggedInUser,
@@ -24,7 +28,7 @@ export default (
2428
setLoggedInUser(resUser);
2529
setLoading(false);
2630
})
27-
.catch((err) => {
31+
.catch((err: firebase.FirebaseError) => {
2832
setError(err);
2933
setLoading(false);
3034
});

auth/useRegister.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import { useState, useMemo } from 'react';
22
import firebase from 'firebase/app';
33
import { AuthHookType } from '../util';
44

5-
export type registerHook = AuthHookType<firebase.auth.UserCredential>;
5+
export type registerHook = AuthHookType<
6+
firebase.auth.UserCredential,
7+
firebase.FirebaseError
8+
>;
69

710
export default (
811
auth: firebase.auth.Auth,
912
email: string,
1013
password: string
1114
): registerHook => {
12-
const [error, setError] = useState<any>(null);
15+
const [error, setError] = useState<firebase.FirebaseError>();
1316
const [
1417
registeredUser,
1518
setRegisteredUser,
@@ -24,7 +27,7 @@ export default (
2427
setRegisteredUser(resUser);
2528
setLoading(false);
2629
})
27-
.catch((err) => {
30+
.catch((err: firebase.FirebaseError) => {
2831
setError(err);
2932
setLoading(false);
3033
});

util/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ export { default as useLoadingValue } from './useLoadingValue';
22
export * from './refHooks';
33

44
export type LoadingHook<T, E> = [T | undefined, boolean, E | undefined];
5-
export type AuthHookType<T> = [T | undefined, any, () => void, boolean];
5+
export type AuthHookType<T, E> = [
6+
T | undefined,
7+
E | undefined,
8+
() => void,
9+
boolean
10+
];

0 commit comments

Comments
 (0)