Skip to content

Commit 44736a6

Browse files
lsiracsamtstern
authored andcommitted
Add a new error dialog for the case where there is an anonymous user mismatch (#1531)
1 parent e19b2e2 commit 44736a6

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public final class ErrorCodes {
6060
* */
6161
public static final int EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR = 10;
6262

63+
/**
64+
* Attempting to open an email link from the same device, with anonymous upgrade enabled,
65+
* but the underlying anonymous user has been changed.
66+
*/
67+
public static final int EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR = 11;
68+
6369
private ErrorCodes() {
6470
throw new AssertionError("No instance for you!");
6571
}
@@ -91,6 +97,9 @@ public static String toFriendlyMessage(@Code int code) {
9197
return "You must open the email link on the same device.";
9298
case EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR:
9399
return "You must determine if you want to continue linking or complete the sign in";
100+
case EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR:
101+
return "The session associated with this sign-in request has either expired or " +
102+
"was cleared";
94103
default:
95104
throw new IllegalArgumentException("Unknown code: " + code);
96105
}
@@ -110,7 +119,8 @@ public static String toFriendlyMessage(@Code int code) {
110119
INVALID_EMAIL_LINK_ERROR,
111120
EMAIL_LINK_WRONG_DEVICE_ERROR,
112121
EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR,
113-
EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR
122+
EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR,
123+
EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR
114124
})
115125
@Retention(RetentionPolicy.SOURCE)
116126
public @interface Code {

auth/src/main/java/com/firebase/ui/auth/ui/email/EmailLinkCatcherActivity.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ protected void onFailure(@NonNull final Exception e) {
6464
} else if (e instanceof FirebaseUiException) {
6565
int errorCode = ((FirebaseUiException) e).getErrorCode();
6666
if (errorCode == ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR
67-
|| errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR) {
67+
|| errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR
68+
|| errorCode == ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR) {
6869
buildAlertDialog(errorCode).show();
6970
} else if (errorCode == ErrorCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR
7071
|| errorCode == ErrorCodes.EMAIL_MISMATCH_ERROR) {
@@ -97,28 +98,32 @@ private void startErrorRecoveryFlow(int flow) {
9798
startActivityForResult(intent, flow);
9899
}
99100

100-
private AlertDialog buildAlertDialog(int errorCode) {
101+
private AlertDialog buildAlertDialog(final int errorCode) {
101102
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
102-
if (errorCode == ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR) {
103-
alertDialog.setTitle(R.string.fui_email_link_wrong_device_header)
104-
.setMessage(R.string.fui_email_link_wrong_device_message)
105-
.setPositiveButton(R.string.fui_email_link_dismiss_button,
106-
new DialogInterface.OnClickListener() {
107-
public void onClick(DialogInterface dialog, int id) {
108-
finish(RequestCodes.EMAIL_LINK_WRONG_DEVICE_FLOW, null);
109-
}
110-
});
103+
104+
String titleText;
105+
String messageText;
106+
if (errorCode == ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR) {
107+
titleText = getString(R.string.fui_email_link_different_anonymous_user_header);
108+
messageText = getString(R.string.fui_email_link_different_anonymous_user_message);
111109
} else if (errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR) {
112-
alertDialog.setTitle(R.string.fui_email_link_invalid_link_header)
113-
.setMessage(R.string.fui_email_link_invalid_link_message)
114-
.setPositiveButton(R.string.fui_email_link_dismiss_button,
115-
new DialogInterface.OnClickListener() {
116-
public void onClick(DialogInterface dialog, int id) {
117-
finish(RequestCodes.EMAIL_LINK_INVALID_LINK_FLOW, null);
118-
}
119-
});
110+
titleText = getString(R.string.fui_email_link_invalid_link_header);
111+
messageText = getString(R.string.fui_email_link_invalid_link_message);
112+
} else {
113+
// Default value - ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR
114+
titleText = getString(R.string.fui_email_link_wrong_device_header);
115+
messageText = getString(R.string.fui_email_link_wrong_device_message);
120116
}
121-
return alertDialog.create();
117+
118+
return alertDialog.setTitle(titleText)
119+
.setMessage(messageText)
120+
.setPositiveButton(R.string.fui_email_link_dismiss_button,
121+
new DialogInterface.OnClickListener() {
122+
public void onClick(DialogInterface dialog, int id) {
123+
finish(errorCode, null);
124+
}
125+
})
126+
.create();
122127
}
123128

124129
@Override

auth/src/main/java/com/firebase/ui/auth/viewmodel/email/EmailLinkSignInHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public void startSignIn() {
8888
if (getAuth().getCurrentUser() == null
8989
|| (getAuth().getCurrentUser().isAnonymous()
9090
&& !anonymousUserIdFromLink.equals(getAuth().getCurrentUser().getUid()))) {
91-
// TODO(lsirac): add new error?
9291
setResult(Resource.<IdpResponse>forFailure(
93-
new FirebaseUiException(ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR)));
92+
new FirebaseUiException(
93+
ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR)));
9494
return;
9595
}
9696
}

auth/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
<string name="fui_email_link_wrong_device_message" translation_description="Message shown when the user opens a link that was sent from a different device">Try opening the link using the same device or browser where you started the sign-in process.</string>
104104
<string name="fui_email_link_invalid_link_header" translation_description="Header shown when the user opens a link that was sent from a different device">Unable to complete sign in</string>
105105
<string name="fui_email_link_invalid_link_message" translation_description="Message shown when the user opens a link that was sent from a different device">The action code is invalid. This can happen if the code is malformed, expired, or has already been used.</string>
106+
<string name="fui_email_link_different_anonymous_user_header" translation_description="Header shown when the user opens a link but the underlying session has changed">Session ended</string>
107+
<string name="fui_email_link_different_anonymous_user_message" translation_description="Message shown when the user opens a link but the underlying session has changed">The session associated with this sign-in request has either expired or was cleared.</string>
106108
<string name="fui_email_link_confirm_email_header" translation_description="Header shown when prompting the user to confirm their email to complete the sign in">Confirm email</string>
107109
<string name="fui_email_link_confirm_email_message" translation_description="Message shown when prompting the user to confirm their email to finish the sign in flow">Confirm email to continue sign in</string>
108110
<string name="fui_email_link_dismiss_button" translation_description="Dismiss button for the wrong device or invalid link dialog">Dismiss</string>

0 commit comments

Comments
 (0)