Skip to content

Commit ae09071

Browse files
authored
fix(android,auth): return correct error code for linkWithCredential provider-already-linked on Android (#8245)
1 parent 32d06e7 commit ae09071

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthPlugin.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,21 @@ private Task<Map<String, Object>> linkUserWithCredential(Map<String, Object> arg
806806
throw FlutterFirebaseAuthPluginException.invalidCredential();
807807
}
808808

809-
AuthResult authResult = Tasks.await(firebaseUser.linkWithCredential(credential));
809+
AuthResult authResult;
810+
811+
try {
812+
authResult = Tasks.await(firebaseUser.linkWithCredential(credential));
813+
} catch (Exception exception) {
814+
String message = exception.getMessage();
815+
816+
if (message != null
817+
&& message.contains("User has already been linked to the given provider.")) {
818+
throw FlutterFirebaseAuthPluginException.alreadyLinkedProvider();
819+
}
820+
821+
throw exception;
822+
}
823+
810824
return parseAuthResult(authResult);
811825
});
812826
}

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthPluginException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ static FlutterFirebaseAuthPluginException noSuchProvider() {
7575
"NO_SUCH_PROVIDER", "User was not linked to an account with the given provider.");
7676
}
7777

78+
static FlutterFirebaseAuthPluginException alreadyLinkedProvider() {
79+
return new FlutterFirebaseAuthPluginException(
80+
"PROVIDER_ALREADY_LINKED", "User has already been linked to the given provider.");
81+
}
82+
7883
public String getCode() {
7984
return code.toLowerCase(Locale.ROOT).replace("error_", "").replace("_", "-");
8085
}

0 commit comments

Comments
 (0)