Skip to content

Commit 585c8bd

Browse files
hoi4Philipp Heuer
andauthored
refactor(android): separate messages for signin exception (#176)
* added status code for android implementation * added iOS error code Co-authored-by: Philipp Heuer <[email protected]>
1 parent 8bd4ce9 commit 585c8bd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public class GoogleAuth extends Plugin {
4343
private final static String FIELD_TOKEN_EXPIRES_IN = "expires_in";
4444
private final static String FIELD_ACCESS_TOKEN = "accessToken";
4545
private final static String FIELD_TOKEN_EXPIRES = "expires";
46+
47+
// see https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes#SIGN_IN_CANCELLED
48+
private final static int SIGN_IN_CANCELLED = 12501;
49+
4650
public static final int KAssumeStaleTokenSec = 60;
4751

4852
private GoogleSignInClient googleSignInClient;
@@ -121,7 +125,11 @@ protected void signInResult(PluginCall call, ActivityResult result) {
121125
}
122126
});
123127
} catch (ApiException e) {
124-
call.reject("Something went wrong", e);
128+
if (SIGN_IN_CANCELLED == e.getStatusCode()) {
129+
call.reject("The user canceled the sign-in flow.", "" + e.getStatusCode());
130+
} else {
131+
call.reject("Something went wrong", "" + e.getStatusCode());
132+
}
125133
}
126134
}
127135

ios/Plugin/Plugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class GoogleAuth: CAPPlugin {
5858

5959
self.googleSignIn.signIn(with: self.googleSignInConfiguration, presenting: presentingVc) { user, error in
6060
if let error = error {
61-
self.signInCall?.reject(error.localizedDescription);
61+
self.signInCall?.reject(error.localizedDescription, "\(error._code)");
6262
return;
6363
}
6464
if self.additionalScopes.count > 0 {

0 commit comments

Comments
 (0)