Skip to content

Commit

Permalink
fix(authentication): NullPointerException when `getPendingAuthResul…
Browse files Browse the repository at this point in the history
…t()` is called (#632)
  • Loading branch information
robingenz committed Jun 5, 2024
1 parent a851a23 commit aa08e71
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-balloons-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/authentication': patch
---

fix(android): `NullPointerException` when `getPendingAuthResult()` is called
Original file line number Diff line number Diff line change
Expand Up @@ -698,59 +698,76 @@ public void handleSuccessfulSignIn(
call.resolve(signInResult);
return;
}
getFirebaseAuthInstance()
.signInWithCredential(credential)
.addOnCompleteListener(
plugin.getActivity(),
task -> {
if (task.isSuccessful()) {
final AuthResult authResult = task.getResult();
handleSuccessfulSignIn(call, authResult, idToken, nonce, accessToken, serverAuthCode);
} else {
Exception exception = task.getException();
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
if (credential == null) {
handleSuccessfulSignIn(call);
} else {
getFirebaseAuthInstance()
.signInWithCredential(credential)
.addOnCompleteListener(
plugin.getActivity(),
task -> {
if (task.isSuccessful()) {
final AuthResult authResult = task.getResult();
handleSuccessfulSignIn(call, authResult, idToken, nonce, accessToken, serverAuthCode);
} else {
Exception exception = task.getException();
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
}
}
}
);
);
}
}

public void handleSuccessfulSignIn(
final PluginCall call,
final AuthResult authResult,
@Nullable AuthResult authResult,
@Nullable String idToken,
@Nullable String nonce,
@Nullable String accessToken
) {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
authResult.getAdditionalUserInfo()
);
call.resolve(signInResult);
if (authResult == null) {
handleSuccessfulSignIn(call);
} else {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
authResult.getAdditionalUserInfo()
);
call.resolve(signInResult);
}
}

public void handleSuccessfulSignIn(
final PluginCall call,
final AuthResult authResult,
@Nullable AuthResult authResult,
@Nullable String idToken,
@Nullable String nonce,
@Nullable String accessToken,
@Nullable String serverAuthCode
) {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
serverAuthCode,
authResult.getAdditionalUserInfo()
);
if (authResult == null) {
handleSuccessfulSignIn(call);
} else {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
serverAuthCode,
authResult.getAdditionalUserInfo()
);
call.resolve(signInResult);
}
}

public void handleSuccessfulSignIn(@NonNull final PluginCall call) {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(null, null, null, null, null, null);
call.resolve(signInResult);
}

Expand All @@ -776,41 +793,54 @@ public void handleSuccessfulLink(
call.reject(FirebaseAuthenticationPlugin.ERROR_NO_USER_SIGNED_IN);
return;
}
user
.linkWithCredential(credential)
.addOnCompleteListener(
plugin.getActivity(),
task -> {
if (task.isSuccessful()) {
final AuthResult authResult = task.getResult();
handleSuccessfulLink(call, authResult, idToken, nonce, accessToken, serverAuthCode);
} else {
Exception exception = task.getException();
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
if (credential == null) {
handleSuccessfulLink(call);
} else {
user
.linkWithCredential(credential)
.addOnCompleteListener(
plugin.getActivity(),
task -> {
if (task.isSuccessful()) {
final AuthResult authResult = task.getResult();
handleSuccessfulLink(call, authResult, idToken, nonce, accessToken, serverAuthCode);
} else {
Exception exception = task.getException();
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
}
}
}
);
);
}
}

public void handleSuccessfulLink(
final PluginCall call,
final AuthResult authResult,
@Nullable AuthResult authResult,
@Nullable String idToken,
@Nullable String nonce,
@Nullable String accessToken,
@Nullable String serverAuthCode
) {
JSObject linkResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
serverAuthCode,
authResult.getAdditionalUserInfo()
);
if (authResult == null) {
handleSuccessfulLink(call);
} else {
JSObject linkResult = FirebaseAuthenticationHelper.createSignInResult(
authResult.getUser(),
authResult.getCredential(),
idToken,
nonce,
accessToken,
serverAuthCode,
authResult.getAdditionalUserInfo()
);
call.resolve(linkResult);
}
}

public void handleSuccessfulLink(final PluginCall call) {
JSObject linkResult = FirebaseAuthenticationHelper.createSignInResult(null, null, null, null, null, null);
call.resolve(linkResult);
}

Expand Down

0 comments on commit aa08e71

Please sign in to comment.