Skip to content

Commit d7c67ae

Browse files
committed
Clear error state when calling functions
1 parent adb0785 commit d7c67ae

File tree

7 files changed

+14
-5
lines changed

7 files changed

+14
-5
lines changed

auth/useCreateUserWithEmailAndPassword.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
Auth,
3-
UserCredential,
3+
AuthError,
44
createUserWithEmailAndPassword as firebaseCreateUserWithEmailAndPassword,
55
sendEmailVerification,
6-
AuthError,
6+
UserCredential,
77
} from 'firebase/auth';
8-
import { useState, useMemo } from 'react';
8+
import { useMemo, useState } from 'react';
99
import { CreateUserOptions, EmailAndPasswordActionHook } from './types';
1010

1111
export default (
@@ -21,6 +21,7 @@ export default (
2121
password: string
2222
) => {
2323
setLoading(true);
24+
setError(undefined);
2425
try {
2526
const user = await firebaseCreateUserWithEmailAndPassword(
2627
auth,

auth/useSendEmailVerification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default (auth: Auth): SendEmailVerificationHook => {
1717

1818
const sendEmailVerification = async () => {
1919
setLoading(true);
20+
setError(undefined);
2021
try {
2122
if (auth.currentUser) {
2223
await fbSendEmailVerification(auth.currentUser);

auth/useSendPasswordResetEmail.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default (auth: Auth): SendPasswordResetEmailHook => {
1717

1818
const sendPasswordResetEmail = async (email: string) => {
1919
setLoading(true);
20+
setError(undefined);
2021
try {
2122
await fbSendPasswordResetEmail(auth, email);
2223
} catch (err) {

auth/useSignInWithPopup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useState, useMemo } from 'react';
21
import {
32
Auth,
43
AuthError,
@@ -8,10 +7,11 @@ import {
87
GithubAuthProvider,
98
GoogleAuthProvider,
109
OAuthProvider,
11-
TwitterAuthProvider,
1210
signInWithPopup,
11+
TwitterAuthProvider,
1312
UserCredential,
1413
} from 'firebase/auth';
14+
import { useMemo, useState } from 'react';
1515
import { SignInWithPopupHook } from './types';
1616

1717
export const useSignInWithApple = (auth: Auth): SignInWithPopupHook => {
@@ -130,6 +130,7 @@ const useSignInWithPopup = (
130130
customOAuthParameters?: CustomParameters
131131
) => {
132132
setLoading(true);
133+
setError(undefined);
133134
try {
134135
const provider = createProvider(scopes, customOAuthParameters);
135136
const user = await signInWithPopup(auth, provider);

auth/useUpdateUser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const useUpdateEmail = (auth: Auth): UpdateEmailHook => {
2828

2929
const updateEmail = async (email: string) => {
3030
setLoading(true);
31+
setError(undefined);
3132
try {
3233
if (auth.currentUser) {
3334
await fbUpdateEmail(auth.currentUser, email);
@@ -51,6 +52,7 @@ export const useUpdatePassword = (auth: Auth): UpdatePasswordHook => {
5152

5253
const updatePassword = async (password: string) => {
5354
setLoading(true);
55+
setError(undefined);
5456
try {
5557
if (auth.currentUser) {
5658
await fbUpdatePassword(auth.currentUser, password);
@@ -74,6 +76,7 @@ export const useUpdateProfile = (auth: Auth): UpdateProfileHook => {
7476

7577
const updateProfile = async (profile: Profile) => {
7678
setLoading(true);
79+
setError(undefined);
7780
try {
7881
if (auth.currentUser) {
7982
await fbUpdateProfile(auth.currentUser, profile);

functions/useHttpsCallable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default <RequestData = unknown, ResponseData = unknown>(
2323
): Promise<HttpsCallableResult<ResponseData> | undefined> => {
2424
const callable = httpsCallable<RequestData, ResponseData>(functions, name);
2525
setLoading(true);
26+
setError(undefined);
2627
try {
2728
return await callable(data);
2829
} catch (err) {

storage/useUploadFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default (): UploadFileHook => {
3131
): Promise<UploadResult | undefined> => {
3232
return new Promise((resolve, reject) => {
3333
setUploading(true);
34+
setError(undefined);
3435
const uploadTask = uploadBytesResumable(storageRef, data, metadata);
3536
uploadTask.on(
3637
'state_changed',

0 commit comments

Comments
 (0)