Skip to content

Commit ad7b8c2

Browse files
committed
Move options to central type
1 parent a3b890d commit ad7b8c2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

auth/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ type AuthActionHook<T, E> = [
66
boolean,
77
E | undefined
88
];
9+
export type CreateUserOptions = {
10+
emailVerificationOptions?: firebase.auth.ActionCodeSettings;
11+
sendEmailVerification?: boolean;
12+
};
913
export type EmailAndPasswordActionHook = AuthActionHook<
1014
firebase.auth.UserCredential,
1115
firebase.FirebaseError

auth/useCreateUserWithEmailAndPassword.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { useState, useMemo } from 'react';
22
import firebase from 'firebase/app';
3-
import { EmailAndPasswordActionHook } from './types';
3+
import { CreateUserOptions, EmailAndPasswordActionHook } from './types';
44

5-
export default (auth: firebase.auth.Auth, options?:{sendEmailVerification?: boolean, emailVerificationOptions?: firebase.auth.ActionCodeSettings}): EmailAndPasswordActionHook => {
5+
export default (
6+
auth: firebase.auth.Auth,
7+
options?: CreateUserOptions
8+
): EmailAndPasswordActionHook => {
69
const [error, setError] = useState<firebase.FirebaseError>();
710
const [
811
registeredUser,
@@ -17,8 +20,8 @@ export default (auth: firebase.auth.Auth, options?:{sendEmailVerification?: bool
1720
setLoading(true);
1821
try {
1922
const user = await auth.createUserWithEmailAndPassword(email, password);
20-
if (options?.sendEmailVerification) {
21-
await user.user.sendEmailVerification(emailVerificationOptions)
23+
if (options && options.sendEmailVerification && user.user) {
24+
await user.user.sendEmailVerification(options.emailVerificationOptions);
2225
}
2326
setRegisteredUser(user);
2427
setLoading(false);

0 commit comments

Comments
 (0)