Skip to content

Commit b5c8cf6

Browse files
authored
added admin_only_operation error (#1707)
1 parent 26d9554 commit b5c8cf6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/auth/src/error_auth.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ fireauth.AuthError.ERROR_CODE_PREFIX = 'auth/';
113113
* @enum {string}
114114
*/
115115
fireauth.authenum.Error = {
116+
ADMIN_ONLY_OPERATION: 'admin-restricted-operation',
116117
ARGUMENT_ERROR: 'argument-error',
117118
APP_NOT_AUTHORIZED: 'app-not-authorized',
118119
APP_NOT_INSTALLED: 'app-not-installed',
@@ -198,6 +199,8 @@ fireauth.authenum.Error = {
198199
* @private {!Object<string, string>}
199200
*/
200201
fireauth.AuthError.MESSAGES_ = {};
202+
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.ADMIN_ONLY_OPERATION] =
203+
'This operation is restricted to administrators only.';
201204
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.ARGUMENT_ERROR] = '';
202205
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.APP_NOT_AUTHORIZED] =
203206
'This app, identified by the domain where it\'s hosted, is not ' +
@@ -277,9 +280,6 @@ fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_CERT_HASH] =
277280
'The SHA-1 certificate hash provided is invalid.';
278281
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_IDP_RESPONSE] =
279282
'The supplied auth credential is malformed or has expired.';
280-
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PERSISTENCE] =
281-
'The specified persistence type is invalid. It can only be local, ' +
282-
'session or none.';
283283
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_MESSAGE_PAYLOAD] =
284284
'The email template corresponding to this action contains invalid charac' +
285285
'ters in its message. Please fix by going to the Auth email templates se' +
@@ -298,6 +298,9 @@ fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_OOB_CODE] =
298298
'expired, or has already been used.';
299299
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PASSWORD] =
300300
'The password is invalid or the user does not have a password.';
301+
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PERSISTENCE] =
302+
'The specified persistence type is invalid. It can only be local, ' +
303+
'session or none.';
301304
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PHONE_NUMBER] =
302305
'The format of the phone number provided is incorrect. Please enter the ' +
303306
'phone number in a format that can be parsed into E.164 format. E.164 ' +

packages/auth/src/rpchandler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ fireauth.RpcHandler.HttpMethod = {
184184
* @enum {string}
185185
*/
186186
fireauth.RpcHandler.ServerError = {
187+
ADMIN_ONLY_OPERATION: 'ADMIN_ONLY_OPERATION',
187188
CAPTCHA_CHECK_FAILED: 'CAPTCHA_CHECK_FAILED',
188189
CORS_UNSUPPORTED: 'CORS_UNSUPPORTED',
189190
CREDENTIAL_MISMATCH: 'CREDENTIAL_MISMATCH',
@@ -2432,6 +2433,10 @@ fireauth.RpcHandler.getDeveloperError_ =
24322433
errorMap[fireauth.RpcHandler.ServerError.INVALID_CERT_HASH] =
24332434
fireauth.authenum.Error.INVALID_CERT_HASH;
24342435

2436+
// User actions (sign-up or deletion) disabled errors.
2437+
errorMap[fireauth.RpcHandler.ServerError.ADMIN_ONLY_OPERATION] =
2438+
fireauth.authenum.Error.ADMIN_ONLY_OPERATION;
2439+
24352440
// Override errors set in the custom map.
24362441
var customErrorMap = opt_customErrorMap || {};
24372442
goog.object.extend(errorMap, customErrorMap);

packages/auth/test/rpchandler_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,8 @@ function testCreateAccount_serverCaughtError() {
28002800
fireauth.authenum.Error.OPERATION_NOT_ALLOWED;
28012801
errorMap[fireauth.RpcHandler.ServerError.WEAK_PASSWORD] =
28022802
fireauth.authenum.Error.WEAK_PASSWORD;
2803+
errorMap[fireauth.RpcHandler.ServerError.ADMIN_ONLY_OPERATION] =
2804+
fireauth.authenum.Error.ADMIN_ONLY_OPERATION;
28032805

28042806
assertServerErrorsAreHandled(function() {
28052807
return rpcHandler.createAccount(email, password);
@@ -2894,6 +2896,8 @@ function testDeleteAccount_serverCaughtError() {
28942896
fireauth.authenum.Error.TOKEN_EXPIRED;
28952897
errorMap[fireauth.RpcHandler.ServerError.USER_DISABLED] =
28962898
fireauth.authenum.Error.USER_DISABLED;
2899+
errorMap[fireauth.RpcHandler.ServerError.ADMIN_ONLY_OPERATION] =
2900+
fireauth.authenum.Error.ADMIN_ONLY_OPERATION;
28972901

28982902
assertServerErrorsAreHandled(function() {
28992903
return rpcHandler.deleteAccount('ID_TOKEN');

0 commit comments

Comments
 (0)