Skip to content

Commit 08ef4b9

Browse files
authored
Release3.4.1 (#502)
- Hides cancel button in phone sign-in page if only phone provider is configured. - Reverts FirebaseUI languageCode modification on external Auth instance before sign in completion - Updated readme and changelog
1 parent 1613901 commit 08ef4b9

18 files changed

+155
-26
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ Localized versions of the widget are available through the CDN. To use a localiz
6868
localized JS library instead of the default library:
6969

7070
```html
71-
<script src="https://www.gstatic.com/firebasejs/ui/3.4.0/firebase-ui-auth__{LANGUAGE_CODE}.js"></script>
72-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/3.4.0/firebase-ui-auth.css" />
71+
<script src="https://www.gstatic.com/firebasejs/ui/3.4.1/firebase-ui-auth__{LANGUAGE_CODE}.js"></script>
72+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/3.4.1/firebase-ui-auth.css" />
7373
```
7474

7575
where `{LANGUAGE_CODE}` is replaced by the code of the language you want. For example, the French
7676
version of the library is available at
77-
`https://www.gstatic.com/firebasejs/ui/3.4.0/firebase-ui-auth__fr.js`. The list of available
77+
`https://www.gstatic.com/firebasejs/ui/3.4.1/firebase-ui-auth__fr.js`. The list of available
7878
languages and their respective language codes can be found at [LANGUAGES.md](LANGUAGES.md).
7979

8080
Right-to-left languages also require the right-to-left version of the stylesheet, available at
81-
`https://www.gstatic.com/firebasejs/ui/3.4.0/firebase-ui-auth-rtl.css`, instead of the default
81+
`https://www.gstatic.com/firebasejs/ui/3.4.1/firebase-ui-auth-rtl.css`, instead of the default
8282
stylesheet. The supported right-to-left languages are Arabic (ar), Farsi (fa), and Hebrew (iw).
8383

8484
### Option 2: npm Module

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fixed - Hides cancel button in phone sign-in page if only phone provider is configured.
2+
fixed - Reverts FirebaseUI languageCode modification on external Auth instance before sign in completion to not trigger race conditions when signInSuccessWithAuthResult callback modifies the Auth languageCode.

javascript/ui/page/phonesigninstart.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ goog.require('goog.dom.selection');
3232
* UI component for the user to enter their phone number.
3333
* @param {function(?)} onSubmitClick Callback to invoke when enter key (or its
3434
* equivalent) is detected on submission.
35-
* @param {function(?)} onCancelClick Callback to invoke when cancel button
36-
* is clicked.
3735
* @param {boolean} enableVisibleRecaptcha Whether to enable visible reCAPTCHA.
36+
* @param {?function(?)=} opt_onCancelClick Callback to invoke when cancel
37+
* button is clicked.
3838
* @param {?function()=} opt_tosCallback Callback to invoke when the ToS link
3939
* is clicked.
4040
* @param {?function()=} opt_privacyPolicyCallback Callback to invoke when the
@@ -52,8 +52,8 @@ goog.require('goog.dom.selection');
5252
*/
5353
firebaseui.auth.ui.page.PhoneSignInStart = function(
5454
onSubmitClick,
55-
onCancelClick,
5655
enableVisibleRecaptcha,
56+
opt_onCancelClick,
5757
opt_tosCallback,
5858
opt_privacyPolicyCallback,
5959
opt_displayFullTosPpMessage,
@@ -69,6 +69,7 @@ firebaseui.auth.ui.page.PhoneSignInStart = function(
6969
{
7070
enableVisibleRecaptcha: enableVisibleRecaptcha,
7171
nationalNumber: nationalNumber,
72+
displayCancelButton: !!opt_onCancelClick,
7273
displayFullTosPpMessage: !!opt_displayFullTosPpMessage
7374
},
7475
opt_domHelper,
@@ -84,7 +85,7 @@ firebaseui.auth.ui.page.PhoneSignInStart = function(
8485
/** @private {?function(?)} On submit click callback. */
8586
this.onSubmitClick_ = onSubmitClick;
8687
/** @private {?function(?)} On cancel click callback. */
87-
this.onCancelClick_ = onCancelClick;
88+
this.onCancelClick_ = opt_onCancelClick || null;
8889
/**
8990
* @private {?firebaseui.auth.data.country.LookupTree} The country
9091
* lookup prefix tree to search country code with.
@@ -101,7 +102,7 @@ firebaseui.auth.ui.page.PhoneSignInStart.prototype.enterDocument = function() {
101102
// Handle a click on the submit button or cancel button.
102103
this.initFormElement(
103104
/** @type {function(?)} */ (this.onSubmitClick_),
104-
/** @type {function(?)} */ (this.onCancelClick_));
105+
this.onCancelClick_ || undefined);
105106
this.setupFocus_();
106107
firebaseui.auth.ui.page.PhoneSignInStart.base(this, 'enterDocument');
107108
};

javascript/ui/page/phonesigninstart_test.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ function createComponent(enableVisibleRecaptcha, opt_tosCallback,
7979
goog.bind(
8080
firebaseui.auth.ui.element.FormTestHelper.prototype.onSubmit,
8181
formTestHelper),
82+
enableVisibleRecaptcha,
8283
goog.bind(
8384
firebaseui.auth.ui.element.FormTestHelper.prototype.onLinkClick,
8485
formTestHelper),
85-
enableVisibleRecaptcha,
8686
opt_tosCallback,
8787
opt_privacyPolicyCallback,
8888
opt_displayFullTosPpMessage,
@@ -232,6 +232,26 @@ function testPhoneSignInStart_defaultCountryNotAvailable() {
232232
}
233233

234234

235+
function testPhoneSignInStart_noOnCancelClick() {
236+
component.dispose();
237+
// Initialize component with no onCancelClick callback.
238+
component = new firebaseui.auth.ui.page.PhoneSignInStart(
239+
goog.bind(
240+
firebaseui.auth.ui.element.FormTestHelper.prototype.onSubmit,
241+
formTestHelper),
242+
true,
243+
null);
244+
component.render(root);
245+
formTestHelper.setComponent(component);
246+
// Reset previous state of form helper.
247+
formTestHelper.resetState();
248+
// Cancel button should be hidden.
249+
assertNull(component.getSecondaryLinkElement());
250+
// Submit button should be available.
251+
assertNotNull(component.getSubmitElement());
252+
}
253+
254+
235255
function testPhoneSignInStart_footer() {
236256
component.dispose();
237257
component = createComponent(false, tosCallback, privacyPolicyCallback);
@@ -305,10 +325,10 @@ function testPhoneSignInStart_pageEvents() {
305325
goog.bind(
306326
firebaseui.auth.ui.element.FormTestHelper.prototype.onSubmit,
307327
formTestHelper),
328+
true,
308329
goog.bind(
309330
firebaseui.auth.ui.element.FormTestHelper.prototype.onLinkClick,
310-
formTestHelper),
311-
true);
331+
formTestHelper));
312332
// Run all page helper tests.
313333
pageTestHelper.runTests(component, root);
314334
}

javascript/widgets/authui.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ firebaseui.auth.AuthUI = function(auth, opt_appId) {
9191
this.auth_ = auth;
9292
/** @private {?string} The original Auth language code. */
9393
this.originalAuthLanguageCode_ = null;
94+
/** @private {boolean} Whether language code requires reverting. */
95+
this.languageCodePendingRevert_ = false;
9496
// Log FirebaseUI on external Auth instance.
9597
firebaseui.auth.AuthUI.logFirebaseUI_(this.auth_);
9698
var tempApp = firebase.initializeApp({
@@ -441,6 +443,8 @@ firebaseui.auth.AuthUI.prototype.start = function(element, config) {
441443
// Sync the language code of Auth instance with widget.
442444
this.auth_.languageCode = unicodeLocale;
443445
this.tempAuth_.languageCode = unicodeLocale;
446+
// At end of flow or on reset, revert is needed.
447+
this.languageCodePendingRevert_ = true;
444448

445449
// There is a problem when config in second call modifies accountchooser.com
446450
// related config. eg. acUiConfig
@@ -655,6 +659,23 @@ firebaseui.auth.AuthUI.prototype.getAuthUiGetter = function() {
655659
};
656660

657661

662+
/**
663+
* Reverts the external Auth instance language code to original setting.
664+
* This should be called right before the widget operation completes.
665+
* However, it should be called before the developer callbacks, in case the
666+
* developer tries to set the language within the callback.
667+
*/
668+
firebaseui.auth.AuthUI.prototype.revertLanguageCode = function() {
669+
// Change back the languageCode of external Auth instance if revert is
670+
// required.
671+
if (typeof this.auth_.languageCode !== 'undefined' &&
672+
this.languageCodePendingRevert_) {
673+
this.languageCodePendingRevert_ = false;
674+
this.auth_.languageCode = this.originalAuthLanguageCode_;
675+
}
676+
};
677+
678+
658679
/** Reset rendered widget and removes it from display. */
659680
firebaseui.auth.AuthUI.prototype.reset = function() {
660681
// Check if instance is already destroyed.
@@ -668,10 +689,7 @@ firebaseui.auth.AuthUI.prototype.reset = function() {
668689
if (this.widgetEventDispatcher_) {
669690
this.widgetEventDispatcher_.unregister();
670691
}
671-
// Change back the languageCode of external Auth instance.
672-
if (typeof this.auth_.languageCode !== 'undefined') {
673-
this.auth_.languageCode = this.originalAuthLanguageCode_;
674-
}
692+
this.revertLanguageCode();
675693
// Removes pending status of previous redirect operations including redirect
676694
// back from accountchooser.com and federated sign in.
677695
firebaseui.auth.storage.removePendingRedirectStatus(this.getAppId());

javascript/widgets/authui_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,32 @@ function testStart_overrideLanguageCode() {
705705
assertEquals('de', testAuth.languageCode);
706706
}
707707

708+
function testStart_revertLanguageCode() {
709+
// Test with explicit call to revertLanguageCode.
710+
// Set the language code of widget to zh-CN.
711+
testStubs.replace(goog, 'LOCALE', 'zh-CN');
712+
createAndInstallTestInstances();
713+
testAuth.install();
714+
app = new firebaseui.auth.AuthUI(testAuth, 'id0');
715+
app.getAuth().assertSetPersistence(['session'], null);
716+
// Set the language code of auth to de.
717+
testAuth.languageCode = 'de';
718+
app.start(container1, config1);
719+
app.getExternalAuth().runAuthChangeHandler();
720+
// External Auth should use UI languageCode.
721+
assertEquals('zh-CN', app.getExternalAuth().languageCode);
722+
assertEquals('zh-CN', testAuth.languageCode);
723+
// Revert languageCode changes.
724+
app.revertLanguageCode();
725+
assertEquals('de', testAuth.languageCode);
726+
// Change languageCode to French.
727+
testAuth.languageCode = 'fr';
728+
app.getAuth().assertSignOut([]);
729+
app.reset();
730+
// Reset should not modify the language after revertLanguageCode.
731+
assertEquals('fr', app.getExternalAuth().languageCode);
732+
}
733+
708734

709735
function testStart_elementNotFound() {
710736
// Test widget start method with missing element.

javascript/widgets/handler/common.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ firebaseui.auth.widget.handler.common.selectFromAccountChooser = function(
420420
*/
421421
firebaseui.auth.widget.handler.common.setLoggedIn =
422422
function(app, component, credential, opt_user, opt_alreadySignedIn) {
423+
// Revert language code at this point to ensure languageCode changes are
424+
// reverted before callbacks are triggered.
425+
app.revertLanguageCode();
423426
if (!!opt_alreadySignedIn) {
424427
// Already signed in on external auth instance.
425428
firebaseui.auth.widget.handler.common.setUserLoggedInExternal_(
@@ -540,6 +543,9 @@ firebaseui.auth.widget.handler.common.setLoggedIn =
540543
*/
541544
firebaseui.auth.widget.handler.common.setLoggedInWithAuthResult =
542545
function(app, component, authResult, opt_alreadySignedIn) {
546+
// Revert language code at this point to ensure languageCode changes are
547+
// reverted before callbacks are triggered.
548+
app.revertLanguageCode();
543549
if (!!opt_alreadySignedIn) {
544550
firebaseui.auth.widget.handler.common
545551
.setUserLoggedInExternalWithAuthResult_(

javascript/widgets/handler/common_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ function testSetLoggedIn() {
281281
var cred = firebase.auth.EmailAuthProvider.credential(
282282
passwordUser['email'], 'password');
283283
testAuth.setUser(passwordUser);
284+
// Confirm revertLanguageCode called on setLoggedIn.
285+
assertNoRevertLanguageCode();
284286
firebaseui.auth.widget.handler.common.setLoggedIn(app, testComponent, cred);
287+
assertRevertLanguageCode(app);
285288
// Sign out from internal instance and then sign in with passed credential to
286289
// external instance.
287290
return testAuth.process().then(function() {
@@ -1202,8 +1205,11 @@ function testSetLoggedInWithAuthResult() {
12021205
'operationType': 'signIn',
12031206
'additionalUserInfo': {'providerId': 'password', 'isNewUser': true}
12041207
};
1208+
// Confirm revertLanguageCode called on setLoggedInWithAuthResult.
1209+
assertNoRevertLanguageCode();
12051210
firebaseui.auth.widget.handler.common.setLoggedInWithAuthResult(
12061211
app, testComponent, internalAuthResult);
1212+
assertRevertLanguageCode(app);
12071213
// Sign out from internal instance and then sign in with passed credential to
12081214
// external instance.
12091215
return testAuth.process().then(function() {

javascript/widgets/handler/phonesigninstart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ firebaseui.auth.widget.handler.handlePhoneSignInStart = function(
9494
// Whether the submission was triggered by a key code.
9595
!!(e && e.keyCode));
9696
},
97+
firebaseui.auth.widget.handler.enableVisibleRecaptcha_,
9798
// On cancel.
98-
function(e) {
99+
isPhoneProviderOnly ? null : function(e) {
99100
// Go back to start sign in handler.
100101
recaptchaVerifier.clear();
101102
component.dispose();
102103
firebaseui.auth.widget.handler.common.handleSignInStart(
103104
app, container);
104105
},
105-
firebaseui.auth.widget.handler.enableVisibleRecaptcha_,
106106
app.getConfig().getTosUrl(),
107107
app.getConfig().getPrivacyPolicyUrl(),
108108
isPhoneProviderOnly,

javascript/widgets/handler/phonesigninstart_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ function testHandlePhoneSignInStart_anonymousUpgrade_credInUseError() {
307307
// Only phone provider is configured, phoneSignInStart is the first page, full
308308
// message should be displayed.
309309
assertPhoneFullMessage(tosCallback, 'http://localhost/privacy_policy');
310+
// Only phone provider is configured, cancel button should be hidden.
311+
assertNull(getCancelButton());
310312
// Confirm reCAPTCHA initialized with expected parameters.
311313
recaptchaVerifierInstance.assertInitializedWithParameters(
312314
getRecaptchaElement(),
@@ -399,6 +401,8 @@ function testHandlePhoneSignInStart_anonymousUpgrade_signInError() {
399401
// Confirm expected page rendered.
400402
assertPhoneSignInStartPage();
401403
assertPhoneFullMessage(null, null);
404+
// Only phone provider is configured, cancel button should be hidden.
405+
assertNull(getCancelButton());
402406
// Confirm reCAPTCHA initialized with expected parameters.
403407
recaptchaVerifierInstance.assertInitializedWithParameters(
404408
getRecaptchaElement(),

javascript/widgets/handler/signin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ firebaseui.auth.widget.handler.handleSignIn = function(
6161
app, container, opt_email);
6262
},
6363
opt_email,
64-
app.getConfig().getTosUrl(),
64+
app.getConfig().getTosUrl(),
6565
app.getConfig().getPrivacyPolicyUrl(),
6666
isPasswordProviderOnly);
6767
component.render(container);

javascript/widgets/handler/testhelper.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ var firebase = {};
155155
var getApp;
156156
var testComponent;
157157

158+
var lastRevertLanguageCodeCall;
159+
158160

159161
function setUp() {
160162
// Used to initialize internal auth instance.
@@ -322,6 +324,14 @@ function setUp() {
322324
firebaseui.auth.AuthUI.prototype,
323325
'cancelOneTapSignIn',
324326
goog.testing.recordFunction());
327+
// Record calls to revertLanguageCode.
328+
lastRevertLanguageCodeCall = null;
329+
testStubs.replace(
330+
firebaseui.auth.AuthUI.prototype,
331+
'revertLanguageCode',
332+
function() {
333+
lastRevertLanguageCodeCall = this;
334+
});
325335
}
326336

327337

@@ -1201,3 +1211,24 @@ function assertSignInFailure(expectedError) {
12011211
// Sign in success should not be called.
12021212
assertUndefined(signInCallbackUser);
12031213
}
1214+
1215+
1216+
1217+
/**
1218+
* Asserts the last revertLanguageCode call was called on the specified
1219+
* AuthUI instance. After assertion, the internal state counter is reset.
1220+
* @param {!firebaseui.auth.AuthUI} app The AuthUI instance to check for
1221+
* revertLanguageCode calls.
1222+
*/
1223+
function assertRevertLanguageCode(app) {
1224+
assertEquals(app, lastRevertLanguageCodeCall);
1225+
lastRevertLanguageCodeCall = null;
1226+
}
1227+
1228+
1229+
/**
1230+
* Asserts no revertLanguageCode call was called.
1231+
*/
1232+
function assertNoRevertLanguageCode() {
1233+
assertNull(lastRevertLanguageCodeCall);
1234+
}

soy/pages.soy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@
666666
{template .phoneSignInStart}
667667
{@param? nationalNumber: string} /** The phone number to prefill. */
668668
{@param? enableVisibleRecaptcha: bool} /** Whether to enable the visible reCAPTCHA. */
669+
{@param? displayCancelButton: bool} /** Whether to display the cancel button. */
669670
{@param? displayFullTosPpMessage: bool} /** Whether to display the full message of ToS and PP. */
670671
<div class="mdl-card mdl-shadow--2dp{sp}
671672
firebaseui-container firebaseui-id-page-phone-sign-in-start">
@@ -685,7 +686,9 @@
685686
</div>
686687
<div class="firebaseui-card-actions">
687688
<div class="firebaseui-form-actions">
688-
{call firebaseui.auth.soy2.element.cancelButton /}
689+
{if $displayCancelButton}
690+
{call firebaseui.auth.soy2.element.cancelButton /}
691+
{/if}
689692
{call firebaseui.auth.soy2.element.submitButton}
690693
{param label kind="text"}
691694
{msg desc="The button that initiates the verification of the phone number provided

0 commit comments

Comments
 (0)