Skip to content

Commit a64f798

Browse files
Adds error handling in the signin handler when fetchProvidersForEmail… (#123)
* Adds error handling in the signin handler when fetchProvidersForEmail throws some error. This was noticed when the email entered passes client validation but fails on backend validation. In that case, we should display and info bar with the backend error. * Fixes minor version for closure builder. Latest version is breaking in Travis integration tests. * Revert previous closure builder version change.
1 parent 3384d04 commit a64f798

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

javascript/widgets/handler/common.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,14 @@ firebaseui.auth.widget.handler.common.handleStartEmailFirstFlow =
887887
undefined,
888888
opt_infoBarMessage);
889889
},
890-
function(error) {}
890+
function(error) {
891+
// The email provided could be an invalid one or some other error
892+
// could occur.
893+
var errorMessage =
894+
firebaseui.auth.widget.handler.common.getErrorMessage(
895+
error);
896+
component.showInfoBar(errorMessage);
897+
}
891898
));
892899
};
893900

javascript/widgets/handler/signin_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,42 @@ function testHandleSignIn() {
7777
}
7878

7979

80+
function testHandleSignIn_accountLookupError() {
81+
// Test when account lookup throws an error.
82+
var expectedError = {
83+
'code': 'auth/invalid-email',
84+
'message': 'The email address is badly formatted.'
85+
};
86+
app.updateConfig('signInOptions', signInOptionsWithScopes);
87+
firebaseui.auth.widget.handler.handleSignIn(app, container);
88+
assertSignInPage();
89+
90+
// Now email input has 'user', which is not a valid email address.
91+
var emailInput = getEmailElement();
92+
// Pass an invalid email that will pass client side validation.
93+
goog.dom.forms.setValue(emailInput, '[email protected]');
94+
goog.testing.events.fireKeySequence(emailInput, goog.events.KeyCodes.ENTER);
95+
assertSignInPage();
96+
97+
// Enter key triggers fetchProvidersForEmail.
98+
goog.testing.events.fireKeySequence(emailInput, goog.events.KeyCodes.ENTER);
99+
100+
testAuth.assertFetchProvidersForEmail(
101+
102+
null,
103+
expectedError);
104+
return testAuth.process().then(function() {
105+
// Should remain on the same page.
106+
assertSignInPage();
107+
// Account should not be remembered.
108+
assertFalse(firebaseui.auth.storage.isRememberAccount(app.getAppId()));
109+
// Error message should be displayed in the info bar.
110+
assertInfoBarMessage(
111+
firebaseui.auth.widget.handler.common.getErrorMessage(expectedError));
112+
});
113+
}
114+
115+
80116
function testHandleSignIn_reset() {
81117
// Test when reset is called after sign-in handler called.
82118
firebaseui.auth.widget.handler.handleSignIn(app, container);

0 commit comments

Comments
 (0)