Skip to content

Commit 38883b7

Browse files
authored
Anonymous Upgrade + SmartLock fix (#1437)
2 parents 8949483 + 933a04f commit 38883b7

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

app/src/main/java/com/firebase/uidemo/auth/AnonymousUpgradeActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public void startAuthUI() {
8383
Intent intent = AuthUI.getInstance().createSignInIntentBuilder()
8484
.setLogo(R.drawable.firebase_auth_120dp)
8585
.setAvailableProviders(providers)
86-
.setIsSmartLockEnabled(false)
8786
.enableAnonymousUsersAutoUpgrade()
8887
.build();
8988
startActivityForResult(intent, RC_SIGN_IN);
@@ -138,12 +137,13 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
138137
}
139138
if (resultCode == RESULT_OK) {
140139
setStatus("Signed in as " + getUserIdentifier(FirebaseAuth.getInstance().getCurrentUser()));
140+
} else if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) {
141+
setStatus("Merge conflict: user already exists.");
142+
mResolveMergeButton.setEnabled(true);
143+
mPendingCredential = response.getCredentialForLinking();
141144
} else {
142-
if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) {
143-
setStatus("Merge conflict: user already exists.");
144-
mResolveMergeButton.setEnabled(true);
145-
mPendingCredential = response.getCredentialForLinking();
146-
}
145+
Toast.makeText(this, "Auth error, see logs", Toast.LENGTH_SHORT).show();
146+
Log.w(TAG, "Error: " + response.getError().getMessage(), response.getError());
147147
}
148148

149149
updateUI();

auth/src/main/java/com/firebase/ui/auth/IdpResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import com.firebase.ui.auth.data.model.User;
2626
import com.firebase.ui.auth.util.ExtraConstants;
27-
import com.google.firebase.auth.AuthResult;
2827
import com.google.firebase.auth.AuthCredential;
28+
import com.google.firebase.auth.AuthResult;
2929
import com.google.firebase.auth.GoogleAuthProvider;
3030
import com.google.firebase.auth.TwitterAuthProvider;
3131

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

auth/src/main/java/com/firebase/ui/auth/ui/idp/SingleSignInActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.firebase.ui.auth.AuthUI;
1313
import com.firebase.ui.auth.ErrorCodes;
14+
import com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException;
1415
import com.firebase.ui.auth.FirebaseUiException;
1516
import com.firebase.ui.auth.IdpResponse;
1617
import com.firebase.ui.auth.data.model.FlowParameters;
@@ -106,7 +107,12 @@ protected void onSuccess(@NonNull IdpResponse response) {
106107

107108
@Override
108109
protected void onFailure(@NonNull Exception e) {
109-
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
110+
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
111+
IdpResponse res = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
112+
finish(RESULT_CANCELED, new Intent().putExtra(ExtraConstants.IDP_RESPONSE, res));
113+
} else {
114+
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
115+
}
110116
}
111117
});
112118

0 commit comments

Comments
 (0)