Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Feature (ios): Link Apple credential when already signed in #1776

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/firebase.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2661,20 +2661,28 @@ class ASAuthorizationControllerDelegateImpl extends NSObject /* implements ASAut
"apple.com", idToken, rawNonce);

// Sign in with Firebase.
FIRAuth.auth().signInWithCredentialCompletion(
fIROAuthCredential,
(authResult: FIRAuthDataResult, error: NSError) => {
if (error) {
this.reject(error.localizedDescription);
} else {
firebase.notifyAuthStateListeners({
loggedIn: true,
user: toLoginResult(authResult.user)
});
this.resolve(toLoginResult(authResult && authResult.user, authResult && authResult.additionalUserInfo));
firebase.appleAuthDelegate = null;
}
const authResultCb = (authResult: FIRAuthDataResult, error: NSError) => {
if (error) {
this.reject(error.localizedDescription);
} else {
firebase.notifyAuthStateListeners({
loggedIn: true,
user: toLoginResult(authResult.user)
});
this.resolve(toLoginResult(authResult && authResult.user, authResult && authResult.additionalUserInfo));
firebase.appleAuthDelegate = null;
}
}

// Link to existing credential or create a new user
// For some reason using a ternary operator or variable to refer to one of these two functions
// and then invoking them that way causes +[FIRUser linkWithCredential:completion:]:
// unrecognized selector sent to class 0x103529690
if (FIRAuth.auth().currentUser) {
FIRAuth.auth().currentUser.linkWithCredentialCompletion(fIROAuthCredential, authResultCb)
} else {
FIRAuth.auth().signInWithCredentialCompletion(fIROAuthCredential, authResultCb)
}
}
}

Expand Down