UNPKG

@aws-amplify/auth

Version:
110 lines (104 loc) 4.59 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.authErrorMessages = exports.NoUserPoolError = exports.AuthError = void 0; // TODO: delete this module when the Auth class is removed. const core_1 = require("@aws-amplify/core"); const AuthErrorStrings_1 = require("./common/AuthErrorStrings"); const logger = new core_1.ConsoleLogger('AuthError'); class AuthError extends Error { constructor(type) { const { message, log } = exports.authErrorMessages[type]; super(message); // Hack for making the custom error class work when transpiled to es5 // TODO: Delete the following 2 lines after we change the build target to >= es2015 this.constructor = AuthError; Object.setPrototypeOf(this, AuthError.prototype); this.name = 'AuthError'; this.log = log || message; logger.error(this.log); } } exports.AuthError = AuthError; class NoUserPoolError extends AuthError { constructor(type) { super(type); // Hack for making the custom error class work when transpiled to es5 // TODO: Delete the following 2 lines after we change the build target to >= es2015 this.constructor = NoUserPoolError; Object.setPrototypeOf(this, NoUserPoolError.prototype); this.name = 'NoUserPoolError'; } } exports.NoUserPoolError = NoUserPoolError; exports.authErrorMessages = { oauthSignInError: { message: AuthErrorStrings_1.AuthErrorStrings.OAUTH_ERROR, log: 'Make sure Cognito Hosted UI has been configured correctly', }, noConfig: { message: AuthErrorStrings_1.AuthErrorStrings.DEFAULT_MSG, log: ` Error: Amplify has not been configured correctly. This error is typically caused by one of the following scenarios: 1. Make sure you're passing the awsconfig object to Amplify.configure() in your app's entry point See https://aws-amplify.github.io/docs/js/authentication#configure-your-app for more information 2. There might be multiple conflicting versions of amplify packages in your node_modules. Refer to our docs site for help upgrading Amplify packages (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) `, }, missingAuthConfig: { message: AuthErrorStrings_1.AuthErrorStrings.DEFAULT_MSG, log: ` Error: Amplify has not been configured correctly. The configuration object is missing required auth properties. This error is typically caused by one of the following scenarios: 1. Did you run \`amplify push\` after adding auth via \`amplify add auth\`? See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information 2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages. `, }, emptyUsername: { message: AuthErrorStrings_1.AuthErrorStrings.EMPTY_USERNAME, }, // TODO: should include a list of valid sign-in types invalidUsername: { message: AuthErrorStrings_1.AuthErrorStrings.INVALID_USERNAME, }, emptyPassword: { message: AuthErrorStrings_1.AuthErrorStrings.EMPTY_PASSWORD, }, emptyCode: { message: AuthErrorStrings_1.AuthErrorStrings.EMPTY_CODE, }, signUpError: { message: AuthErrorStrings_1.AuthErrorStrings.SIGN_UP_ERROR, log: 'The first parameter should either be non-null string or object', }, noMFA: { message: AuthErrorStrings_1.AuthErrorStrings.NO_MFA, }, invalidMFA: { message: AuthErrorStrings_1.AuthErrorStrings.INVALID_MFA, }, emptyChallengeResponse: { message: AuthErrorStrings_1.AuthErrorStrings.EMPTY_CHALLENGE, }, noUserSession: { message: AuthErrorStrings_1.AuthErrorStrings.NO_USER_SESSION, }, deviceConfig: { message: AuthErrorStrings_1.AuthErrorStrings.DEVICE_CONFIG, }, networkError: { message: AuthErrorStrings_1.AuthErrorStrings.NETWORK_ERROR, }, autoSignInError: { message: AuthErrorStrings_1.AuthErrorStrings.AUTOSIGNIN_ERROR, }, default: { message: AuthErrorStrings_1.AuthErrorStrings.DEFAULT_MSG, }, }; //# sourceMappingURL=Errors.js.map