Skip to content

Commit eff21b6

Browse files
authored
feat: support disable new email user sign up (#826)
* Add support for disabling new email user sign up.
1 parent a3fd135 commit eff21b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1456
-138
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* Fixes `signInFailure` return type to also include void to match external documentation. Fixes
2-
https://github.com/firebase/firebaseui-web/issues/770
1+
* Adds support for disabling new user sign up in email providers, disable new user sign up via project settings and blocking functions.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,19 @@ You can configure either email/password or email/link sign-in with FirebaseUI by
878878
providing the relevant object in the configuration <code>signInOptions</code>
879879
array.
880880

881+
You can disable new user sign up with email providers by setting the flag
882+
`disableSignUp.status` to `true`. This will display an error message when new
883+
users attempt to sign up.
884+
885+
Note that this flag will only disable sign up from the UI and will not prevent
886+
sign up via REST API. It is highly recommended that Identity Platform projects
887+
enforce this policy via one of these 2 mechanisms:
888+
889+
- Blocking functions: Set a `beforeCreate` trigger to disable sign up for email
890+
providers.
891+
- In the Cloud Console / Settings / USERS tab, uncheck `Enable create (sign-up)`
892+
checkbox. Though for this setting, sign up for all providers will be disabled.
893+
881894
<table>
882895
<thead>
883896
<tr>
@@ -949,6 +962,21 @@ array.
949962
This is only relevant to email link sign-in.
950963
</td>
951964
</tr>
965+
<tr>
966+
<td>disableSignUp</td>
967+
<td><code>firebaseui.auth.DisableSignUpConfig</code></td>
968+
<td>No</td>
969+
<td>
970+
The object for configuring `disableSignUp` options, contains 3 fields:
971+
`status(boolean)`: Whether disable user from signing up with email providers
972+
(email/password or email link).
973+
`adminEmail(string|undefined)`: The optional site administrator email to
974+
contact for access when sign up is disabled, for example: `[email protected]`.
975+
`helpLink(string|undefined)`: The optional help link to provide information
976+
on how to get access to the site when sign up is disabled. For example:
977+
`https://www.example.com/trouble_signing_in`.
978+
</td>
979+
</tr>
952980
</tbody>
953981
</table>
954982

demo/public/app.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ function getUiConfig() {
6060
provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
6161
// Whether the display name should be displayed in Sign Up page.
6262
requireDisplayName: true,
63-
signInMethod: getEmailSignInMethod()
63+
signInMethod: getEmailSignInMethod(),
64+
disableSignUp: {
65+
status: getDisableSignUpStatus()
66+
}
6467
},
6568
{
6669
provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
@@ -183,17 +186,20 @@ var deleteAccount = function() {
183186

184187

185188
/**
186-
* Handles when the user changes the reCAPTCHA or email signInMethod config.
189+
* Handles when the user changes the reCAPTCHA, email signInMethod or email
190+
* disableSignUp config.
187191
*/
188192
function handleConfigChange() {
189193
var newRecaptchaValue = document.querySelector(
190194
'input[name="recaptcha"]:checked').value;
191195
var newEmailSignInMethodValue = document.querySelector(
192196
'input[name="emailSignInMethod"]:checked').value;
197+
var currentDisableSignUpStatus =
198+
document.getElementById("email-disableSignUp-status").checked;
193199
location.replace(
194200
location.pathname + '#recaptcha=' + newRecaptchaValue +
195-
'&emailSignInMethod=' + newEmailSignInMethodValue);
196-
201+
'&emailSignInMethod=' + newEmailSignInMethodValue +
202+
'&disableEmailSignUpStatus=' + currentDisableSignUpStatus);
197203
// Reset the inline widget so the config changes are reflected.
198204
ui.reset();
199205
ui.start('#firebaseui-container', getUiConfig());
@@ -233,6 +239,10 @@ var initApp = function() {
233239
document.querySelector(
234240
'input[name="emailSignInMethod"][value="' + getEmailSignInMethod() + '"]')
235241
.checked = true;
242+
document.getElementById('email-disableSignUp-status').addEventListener(
243+
'change', handleConfigChange);
244+
document.getElementById("email-disableSignUp-status").checked =
245+
getDisableSignUpStatus();
236246
};
237247

238248
window.addEventListener('load', initApp);

demo/public/common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ function getEmailSignInMethod() {
3636
}
3737

3838

39+
/**
40+
* @return {boolean} The disable sign up status from the configuration.
41+
*/
42+
function getDisableSignUpStatus() {
43+
var config = parseQueryString(location.hash);
44+
return config['disableEmailSignUpStatus'] === 'true';
45+
}
46+
47+
3948
/**
4049
* @param {string} queryString The full query string.
4150
* @return {!Object<string, string>} The parsed query parameters.

demo/public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ <h4>You are signed out.</h4>
5757
<input type="radio" id="email-signInMethod-emailLink" name="emailSignInMethod"
5858
value="emailLink">
5959
Email Link
60-
</label>
60+
</label><br>
61+
<label for="disableEmailSignUpStatus">Disable email sign up:</label>
62+
<input type="checkbox" id="email-disableSignUp-status" name="disableEmailSignUpStatus">
6163
</fieldset>
6264
<p>
6365
<button id="sign-in-with-redirect">Sign In with Redirect</button>

demo/public/widget.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
firebase.auth.GithubAuthProvider.PROVIDER_ID,
4545
{
4646
provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
47-
signInMethod: getEmailSignInMethod()
47+
signInMethod: getEmailSignInMethod(),
48+
disableSignUp: {
49+
status: getDisableSignUpStatus()
50+
}
4851
},
4952
{
5053
provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,

externs/firebaseui-externs.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,38 @@ firebaseui.auth.OidcSignInOption.prototype.iconUrl;
930930
firebaseui.auth.OidcSignInOption.prototype.customParameters;
931931

932932

933+
/**
934+
* Defines configurations for disabling email sign up.
935+
*
936+
* @interface
937+
*/
938+
firebaseui.auth.DisableSignUpConfig = function() {};
939+
940+
/**
941+
* Whether new user sign up with email/password or email link is disabled.
942+
* The default is false.
943+
*
944+
* @type {boolean}
945+
*/
946+
firebaseui.auth.DisableSignUp.prototype.status;
947+
948+
/**
949+
* The optional site administrator email to contact for access when sign up is
950+
* disabled.
951+
*
952+
* @type {string|undefined}
953+
*/
954+
firebaseui.auth.DisableSignUp.prototype.adminEmail;
955+
956+
/**
957+
* The optional help link to provide information on how to get access to the
958+
* site when sign up is disabled.
959+
*
960+
* @type {string|undefined}
961+
*/
962+
firebaseui.auth.DisableSignUp.prototype.helpLink;
963+
964+
933965
/**
934966
* Defines the sign-in option needed to configure the FirebaseUI email sign-in
935967
* widget.
@@ -964,6 +996,12 @@ firebaseui.auth.EmailSignInOption.prototype.signInMethod;
964996
*/
965997
firebaseui.auth.EmailSignInOption.prototype.forceSameDevice;
966998

999+
/**
1000+
* The object for configuring disableSignUp options.
1001+
* @type {firebaseui.auth.DisableSignUpConfig|undefined}
1002+
*/
1003+
firebaseui.auth.EmailSignInOption.prototype.disableSignUp;
1004+
9671005
/**
9681006
* Defines the optional callback function to return
9691007
* `firebase.auth.ActionCodeSettings` configuration to use when sending the

javascript/testing/auth.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const MockHelper = goog.require('firebaseui.auth.testing.MockHelper');
2525
const Uri = goog.require('goog.Uri');
2626
const array = goog.require('goog.array');
2727

28-
2928
/**
3029
* Fake Auth API client class.
3130
*/

javascript/ui/element/dialog_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ goog.setTestOnly('firebaseui.auth.ui.dialogTest');
1717
goog.require('firebaseui.auth.soy2.element');
1818
goog.require('firebaseui.auth.ui.element');
1919
goog.require('firebaseui.auth.ui.element.dialog');
20+
goog.require('firebaseui.auth.ui.mdl');
2021
goog.require('goog.dom');
22+
goog.require('goog.dom.TagName');
2123
goog.require('goog.math.Coordinate');
2224
goog.require('goog.soy');
2325
goog.require('goog.testing.MockControl');

javascript/ui/element/elementtesthelper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ goog.require('goog.object');
2828
goog.require('goog.testing.events');
2929
goog.require('goog.testing.events.Event');
3030
goog.require('goog.ui.Component');
31+
goog.requireType('goog.events.KeyCodes');
3132

3233

3334

0 commit comments

Comments
 (0)