From 8cc6f994cd8e9c3210032ef305ce052b58a1ac03 Mon Sep 17 00:00:00 2001 From: Andrei Lesnitsky Date: Thu, 2 Nov 2023 14:41:31 +0100 Subject: [PATCH] fix(ui_oauth_apple): fix AuthAction.link for Apple Sign In --- .../lib/src/provider.dart | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/firebase_ui_oauth_apple/lib/src/provider.dart b/packages/firebase_ui_oauth_apple/lib/src/provider.dart index 501b2881..fe5d28ee 100644 --- a/packages/firebase_ui_oauth_apple/lib/src/provider.dart +++ b/packages/firebase_ui_oauth_apple/lib/src/provider.dart @@ -56,15 +56,18 @@ class AppleProvider extends OAuthProvider { void mobileSignIn(AuthAction action) { authListener.onBeforeSignIn(); - auth.signInWithProvider(firebaseAuthProvider).then((userCred) { - if (action == AuthAction.signIn) { - authListener.onSignedIn(userCred); - } else { - authListener.onCredentialLinked(userCred.credential!); - } - }).catchError((err) { - authListener.onError(err); - }); + if (action == AuthAction.link) { + auth.currentUser + ?.linkWithProvider(firebaseAuthProvider) + .then(_onLinked) + .catchError(authListener.onError); + return; + } + + auth + .signInWithProvider(firebaseAuthProvider) + .then(authListener.onSignedIn) + .catchError(authListener.onError); } @override @@ -92,4 +95,8 @@ class AppleProvider extends OAuthProvider { platform == TargetPlatform.iOS || platform == TargetPlatform.macOS; } + + void _onLinked(fba.UserCredential userCredential) { + authListener.onCredentialLinked(userCredential.credential!); + } }