@@ -616,16 +616,16 @@ - (void)signInWithGameCenterCredential:(FIRGameCenterAuthCredential *)credential
616
616
}];
617
617
}
618
618
619
- /* * @fn internalSignInWithEmail :link:completion:
619
+ /* * @fn internalSignInAndRetrieveDataWithEmail :link:completion:
620
620
@brief Signs in using an email and email sign-in link.
621
621
@param email The user's email address.
622
622
@param link The email sign-in link.
623
623
@param callback A block which is invoked when the sign in finishes (or is cancelled.) Invoked
624
624
asynchronously on the global auth work queue in the future.
625
625
*/
626
- - (void )internalSignInWithEmail : (nonnull NSString *)email
627
- link : (nonnull NSString *)link
628
- callback : (nullable FIRAuthResultCallback )callback {
626
+ - (void )internalSignInAndRetrieveDataWithEmail : (nonnull NSString *)email
627
+ link : (nonnull NSString *)link
628
+ callback : (nullable FIRAuthDataResultCallback )callback {
629
629
if (![self isSignInWithEmailLink: link]) {
630
630
[FIRAuthExceptionUtils raiseInvalidParameterExceptionWithReason:
631
631
kInvalidEmailSignInLinkExceptionMessage ];
@@ -647,14 +647,34 @@ - (void)internalSignInWithEmail:(nonnull NSString *)email
647
647
callback: ^(FIREmailLinkSignInResponse *_Nullable response,
648
648
NSError *_Nullable error) {
649
649
if (error) {
650
- callback (nil , error);
650
+ if (callback) {
651
+ callback (nil , error);
652
+ }
651
653
return ;
652
654
}
653
655
[self completeSignInWithAccessToken: response.IDToken
654
656
accessTokenExpirationDate: response.approximateExpirationDate
655
657
refreshToken: response.refreshToken
656
658
anonymous: NO
657
- callback: callback];
659
+ callback: ^(FIRUser *_Nullable user, NSError *_Nullable error) {
660
+ if (error) {
661
+ if (callback) {
662
+ callback (nil , error);
663
+ }
664
+ return ;
665
+ }
666
+ FIRAdditionalUserInfo *additionalUserInfo =
667
+ [[FIRAdditionalUserInfo alloc ] initWithProviderID: FIREmailAuthProviderID
668
+ profile: nil
669
+ username: nil
670
+ isNewUser: response.isNewUser];
671
+ FIRAuthDataResult *result = user ?
672
+ [[FIRAuthDataResult alloc ] initWithUser: user
673
+ additionalUserInfo: additionalUserInfo] : nil ;
674
+ if (callback) {
675
+ callback (result, error);
676
+ }
677
+ }];
658
678
}];
659
679
}
660
680
@@ -695,27 +715,31 @@ - (void)internalSignInAndRetrieveDataWithCredential:(FIRAuthCredential *)credent
695
715
// Special case for email/password credentials
696
716
FIREmailPasswordAuthCredential *emailPasswordCredential =
697
717
(FIREmailPasswordAuthCredential *)credential;
698
- FIRAuthResultCallback completeEmailSignIn = ^(FIRUser *user, NSError *error) {
699
- if (callback) {
700
- if (error) {
701
- callback (nil , error);
702
- return ;
703
- }
704
- FIRAdditionalUserInfo *additionalUserInfo =
705
- [[FIRAdditionalUserInfo alloc ] initWithProviderID: FIREmailAuthProviderID
706
- profile: nil
707
- username: nil
708
- isNewUser: NO ];
709
- FIRAuthDataResult *result = [[FIRAuthDataResult alloc ] initWithUser: user
710
- additionalUserInfo: additionalUserInfo];
711
- callback (result, error);
712
- }
713
- };
718
+
714
719
if (emailPasswordCredential.link ) {
715
- [self internalSignInWithEmail: emailPasswordCredential.email
716
- link: emailPasswordCredential.link
717
- callback: completeEmailSignIn];
720
+ // Email link sign in
721
+ [self internalSignInAndRetrieveDataWithEmail: emailPasswordCredential.email
722
+ link: emailPasswordCredential.link
723
+ callback: callback];
718
724
} else {
725
+ // Email password sign in
726
+ FIRAuthResultCallback completeEmailSignIn = ^(FIRUser *user, NSError *error) {
727
+ if (callback) {
728
+ if (error) {
729
+ callback (nil , error);
730
+ return ;
731
+ }
732
+ FIRAdditionalUserInfo *additionalUserInfo =
733
+ [[FIRAdditionalUserInfo alloc ] initWithProviderID: FIREmailAuthProviderID
734
+ profile: nil
735
+ username: nil
736
+ isNewUser: NO ];
737
+ FIRAuthDataResult *result = [[FIRAuthDataResult alloc ] initWithUser: user
738
+ additionalUserInfo: additionalUserInfo];
739
+ callback (result, error);
740
+ }
741
+ };
742
+
719
743
[self signInWithEmail: emailPasswordCredential.email
720
744
password: emailPasswordCredential.password
721
745
callback: completeEmailSignIn];
0 commit comments