Skip to content

Commit 05a284c

Browse files
DellaBittaa-maurice
authored andcommitted
Code sample for Apple Sign In on link failure for CPP and Unity deviste.
PiperOrigin-RevId: 312670894
1 parent 3d8a869 commit 05a284c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

auth/samples/src/doc_samples.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,32 @@ void UnLinkCredential(const char* providerId, firebase::auth::Auth* auth) {
545545
// [END user_unlink]
546546
}
547547

548+
void LinkCredentialFailAppleSignIn(const firebase::auth::Credential& credential,
549+
firebase::auth::Auth* auth) {
550+
// [START link_credential_apple_signin]
551+
firebase::Future<firebase::auth::SignInResult> link_result =
552+
auth->current_user()->LinkAndRetrieveDataWithCredential(credential);
553+
554+
// To keep example simple, wait on the current thread until call completes.
555+
while (link_result.status() == firebase::kFutureStatusPending) {
556+
Wait(100);
557+
}
558+
559+
// Determine the result of the link attempt
560+
if (link_result.error() == firebase::auth::kAuthErrorNone) {
561+
// user linked correctly.
562+
} else if (link_result.error() ==
563+
firebase::auth::kAuthErrorCredentialAlreadyInUse &&
564+
link_result.result()->info.updated_credential.is_valid()) {
565+
// Sign In with the new credential
566+
firebase::Future<firebase::auth::User*> result = auth->SignInWithCredential(
567+
link_result.result()->info.updated_credential);
568+
} else {
569+
// Another link error occurred.
570+
}
571+
// [END link_credential_apple_signin]
572+
}
573+
548574
void MergeCredentials(const firebase::auth::Credential& credential,
549575
firebase::auth::Auth* auth) {
550576
// [START user_merge]

0 commit comments

Comments
 (0)