Skip to content

Commit fec264d

Browse files
committed
Implement additional FUIAuth sign-in call back which returns FIRAuthDataResult
1 parent e2042d3 commit fec264d

File tree

4 files changed

+46
-52
lines changed

4 files changed

+46
-52
lines changed

FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperationForgotPassword.m

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,26 @@ - (void)onPasswordRecovery:(NSString *)email {
6565

6666
[self.delegate.auth sendPasswordResetWithEmail:email
6767
completion:^(NSError *_Nullable error) {
68-
// The dispatch is a workaround for a bug in FirebaseAuth 3.0.2, which doesn't call the
69-
// completion block on the main queue.
70-
dispatch_async(dispatch_get_main_queue(), ^{
71-
[self.delegate decrementActivity];
68+
[self.delegate decrementActivity];
7269

73-
if (error) {
74-
[self finishOperationWithError:error];
75-
return;
76-
}
70+
if (error) {
71+
[self finishOperationWithError:error];
72+
return;
73+
}
7774

78-
NSString *message = [NSString stringWithFormat:
79-
FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email];
80-
UIAlertController *alertController =
81-
[UIAlertController alertControllerWithTitle:nil
82-
message:message
83-
preferredStyle:UIAlertControllerStyleAlert];
84-
UIAlertAction *okAction = [UIAlertAction actionWithTitle:FUILocalizedString(kStr_OK)
85-
style:UIAlertActionStyleDefault
86-
handler:^(UIAlertAction *_Nonnull action) {
87-
[self finishOperationWithError:error];
88-
}];
89-
[alertController addAction:okAction];
90-
[self.delegate presentViewController:alertController];
91-
});
75+
NSString *message = [NSString stringWithFormat:
76+
FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email];
77+
UIAlertController *alertController =
78+
[UIAlertController alertControllerWithTitle:nil
79+
message:message
80+
preferredStyle:UIAlertControllerStyleAlert];
81+
UIAlertAction *okAction = [UIAlertAction actionWithTitle:FUILocalizedString(kStr_OK)
82+
style:UIAlertActionStyleDefault
83+
handler:^(UIAlertAction *_Nonnull action) {
84+
[self finishOperationWithError:error];
85+
}];
86+
[alertController addAction:okAction];
87+
[self.delegate presentViewController:alertController];
9288
}];
9389
}
9490

FirebaseAuthUI/FUIAuth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef void (^FUIAuthResultCallback)(FIRUser *_Nullable user, NSError *_Nullabl
7070
didSignInWithUser:(nullable FIRUser *)user
7171
error:(nullable NSError *)error
7272
__attribute__((deprecated("This is deprecated API and will be removed in a future release."
73-
"Use authUI:didSignInWithAuthDataResult:error:")));
73+
"Instead use authUI:didSignInWithAuthDataResult:error:")));
7474

7575

7676
/** @fn authUI:didFinishOperation:error:

FirebaseAuthUI/FUIAuth.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,22 @@ - (void)signInWithProviderUI:(id<FUIAuthProvider>)providerUI
186186
return;
187187
}
188188

189-
if (result) {
190-
result(authResult.user, error);
191-
}
192-
193189
if (error) {
194-
[self invokeResultCallbackWithAuthDataResult:authResult error:error];
190+
if (result) {
191+
result(nil, error);
192+
}
193+
[self invokeResultCallbackWithAuthDataResult:nil error:error];
195194
} else {
195+
if (result) {
196+
result(authResult.user, nil);
197+
}
196198
// Hide Auth Picker Controller which was presented modally.
197199
if (isAuthPickerShown && presentingViewController.presentingViewController) {
198200
[presentingViewController dismissViewControllerAnimated:YES completion:^{
199-
[self invokeResultCallbackWithAuthDataResult:authResult error:error];
201+
[self invokeResultCallbackWithAuthDataResult:authResult error:nil];
200202
}];
201203
} else {
202-
[self invokeResultCallbackWithAuthDataResult:authResult error:error];
204+
[self invokeResultCallbackWithAuthDataResult:authResult error:nil];
203205
}
204206
}
205207
}];

FirebaseAuthUI/FUIPasswordRecoveryViewController.m

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,24 @@ - (void)recoverEmail:(NSString *)email {
121121

122122
[self.auth sendPasswordResetWithEmail:email
123123
completion:^(NSError *_Nullable error) {
124-
// The dispatch is a workaround for a bug in FirebaseAuth 3.0.2, which doesn't call the
125-
// completion block on the main queue.
126-
dispatch_async(dispatch_get_main_queue(), ^{
127-
[self decrementActivity];
128-
129-
if (error) {
130-
if (error.code == FIRAuthErrorCodeUserNotFound) {
131-
[self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)];
132-
return;
133-
}
134-
135-
[self.navigationController dismissViewControllerAnimated:YES completion:^{
136-
[self.authUI invokeResultCallbackWithAuthDataResult:nil error:error];
137-
}];
138-
return;
139-
}
140-
141-
NSString *message =
142-
[NSString stringWithFormat:FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email];
143-
[self showAlertWithMessage:message];
144-
});
145-
}];
124+
[self decrementActivity];
125+
126+
if (error) {
127+
if (error.code == FIRAuthErrorCodeUserNotFound) {
128+
[self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)];
129+
return;
130+
}
131+
132+
[self.navigationController dismissViewControllerAnimated:YES completion:^{
133+
[self.authUI invokeResultCallbackWithAuthDataResult:nil error:error];
134+
}];
135+
return;
136+
}
137+
138+
NSString *message = [NSString stringWithFormat:
139+
FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email];
140+
[self showAlertWithMessage:message];
141+
}];
146142
}
147143

148144
- (void)textFieldDidChange {

0 commit comments

Comments
 (0)