Skip to content

Commit

Permalink
Anonymous linking smart lock fix
Browse files Browse the repository at this point in the history
Change-Id: Id73e687690158da56b640695849a863accb89f7a
  • Loading branch information
samtstern committed Sep 6, 2018
1 parent 8949483 commit bd98b15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Expand Up @@ -83,7 +83,7 @@ public void startAuthUI() {
Intent intent = AuthUI.getInstance().createSignInIntentBuilder()
.setLogo(R.drawable.firebase_auth_120dp)
.setAvailableProviders(providers)
.setIsSmartLockEnabled(false)
// .setIsSmartLockEnabled(false)
.enableAnonymousUsersAutoUpgrade()
.build();
startActivityForResult(intent, RC_SIGN_IN);
Expand Down Expand Up @@ -138,12 +138,13 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
}
if (resultCode == RESULT_OK) {
setStatus("Signed in as " + getUserIdentifier(FirebaseAuth.getInstance().getCurrentUser()));
} else if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) {
setStatus("Merge conflict: user already exists.");
mResolveMergeButton.setEnabled(true);
mPendingCredential = response.getCredentialForLinking();
} else {
if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) {
setStatus("Merge conflict: user already exists.");
mResolveMergeButton.setEnabled(true);
mPendingCredential = response.getCredentialForLinking();
}
Toast.makeText(this, "Auth error, see logs", Toast.LENGTH_SHORT).show();
Log.w(TAG, "Error: " + response.getError().getMessage(), response.getError());
}

updateUI();
Expand Down
7 changes: 4 additions & 3 deletions auth/src/main/java/com/firebase/ui/auth/IdpResponse.java
Expand Up @@ -24,8 +24,8 @@

import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.util.ExtraConstants;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.TwitterAuthProvider;

Expand Down Expand Up @@ -244,8 +244,9 @@ public void writeToParcel(Parcel dest, int flags) {
// Somewhere down the line, the exception is holding on to an object that isn't
// serializable so default to some exception. It's the best we can do in this case.
FirebaseUiException fake = new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR,
"Fake exception created, original: " + mException
+ ", original cause: " + mException.getCause());
"Exception serialization error, forced wrapping. " +
"Original: " + mException +
", original cause: " + mException.getCause());
fake.setStackTrace(mException.getStackTrace());
dest.writeSerializable(fake);
} finally {
Expand Down
Expand Up @@ -11,6 +11,7 @@

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException;
import com.firebase.ui.auth.FirebaseUiException;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.data.model.FlowParameters;
Expand Down Expand Up @@ -106,7 +107,12 @@ protected void onSuccess(@NonNull IdpResponse response) {

@Override
protected void onFailure(@NonNull Exception e) {
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
IdpResponse res = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
finish(RESULT_CANCELED, new Intent().putExtra(ExtraConstants.IDP_RESPONSE, res));
} else {
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
}
}
});

Expand Down

0 comments on commit bd98b15

Please sign in to comment.