@@ -16,18 +16,20 @@ type Profile = {
16
16
17
17
export type UpdateUserHook < M > = [ M , boolean , AuthError | Error | undefined ] ;
18
18
19
- export type UpdateEmailHook = UpdateUserHook < ( email : string ) => Promise < void > > ;
19
+ export type UpdateEmailHook = UpdateUserHook <
20
+ ( email : string ) => Promise < boolean >
21
+ > ;
20
22
export type UpdatePasswordHook = UpdateUserHook <
21
- ( password : string ) => Promise < void >
23
+ ( password : string ) => Promise < boolean >
22
24
> ;
23
25
export type UpdateProfileHook = UpdateUserHook <
24
- ( profile : Profile ) => Promise < void >
26
+ ( profile : Profile ) => Promise < boolean >
25
27
> ;
26
28
export type VerifyBeforeUpdateEmailHook = UpdateUserHook <
27
29
(
28
30
email : string ,
29
31
actionCodeSettings : ActionCodeSettings | null
30
- ) => Promise < void >
32
+ ) => Promise < boolean >
31
33
> ;
32
34
33
35
export const useUpdateEmail = ( auth : Auth ) : UpdateEmailHook => {
@@ -41,11 +43,13 @@ export const useUpdateEmail = (auth: Auth): UpdateEmailHook => {
41
43
try {
42
44
if ( auth . currentUser ) {
43
45
await fbUpdateEmail ( auth . currentUser , email ) ;
46
+ return true ;
44
47
} else {
45
- setError ( new Error ( 'No user is logged in' ) as AuthError ) ;
48
+ throw new Error ( 'No user is logged in' ) ;
46
49
}
47
50
} catch ( err ) {
48
51
setError ( err as AuthError ) ;
52
+ return false ;
49
53
} finally {
50
54
setLoading ( false ) ;
51
55
}
@@ -67,11 +71,13 @@ export const useUpdatePassword = (auth: Auth): UpdatePasswordHook => {
67
71
try {
68
72
if ( auth . currentUser ) {
69
73
await fbUpdatePassword ( auth . currentUser , password ) ;
74
+ return true ;
70
75
} else {
71
- setError ( new Error ( 'No user is logged in' ) as AuthError ) ;
76
+ throw new Error ( 'No user is logged in' ) ;
72
77
}
73
78
} catch ( err ) {
74
79
setError ( err as AuthError ) ;
80
+ return false ;
75
81
} finally {
76
82
setLoading ( false ) ;
77
83
}
@@ -93,11 +99,13 @@ export const useUpdateProfile = (auth: Auth): UpdateProfileHook => {
93
99
try {
94
100
if ( auth . currentUser ) {
95
101
await fbUpdateProfile ( auth . currentUser , profile ) ;
102
+ return true ;
96
103
} else {
97
- setError ( new Error ( 'No user is logged in' ) as AuthError ) ;
104
+ throw new Error ( 'No user is logged in' ) ;
98
105
}
99
106
} catch ( err ) {
100
107
setError ( err as AuthError ) ;
108
+ return false ;
101
109
} finally {
102
110
setLoading ( false ) ;
103
111
}
@@ -125,11 +133,13 @@ export const useVerifyBeforeUpdateEmail = (
125
133
email ,
126
134
actionCodeSettings
127
135
) ;
136
+ return true ;
128
137
} else {
129
- setError ( new Error ( 'No user is logged in' ) as AuthError ) ;
138
+ throw new Error ( 'No user is logged in' ) ;
130
139
}
131
140
} catch ( err ) {
132
141
setError ( err as AuthError ) ;
142
+ return false ;
133
143
} finally {
134
144
setLoading ( false ) ;
135
145
}
0 commit comments