question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List of Cognito authentication error codes and messages

See original GitHub issue

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

Authentication

Is this related to another service?

Cognito

Describe the feature you’d like to request

I would like to be able to find a list of common Cognito authentication error codes and messages so that I could provide a mapping for translation purposes.

Describe the solution you’d like

Either one of the following would be ideal:

OR/AND

  • Documentation article which provides this list of error codes/messages

So that I could do something like this:

try {
  await Auth.signIn(email, password);
} catch(error) {
  const { code, message }: { code: AuthSignInErrorCode | undefined, message: AuthSignInErrorMessage | undefined } = error;
  switch(code) {
    case AuthSignInErrorCode.USER_NOT_CONFIRMED: {
      // do something if user is not confirmed
    }
  }
}

Describe alternatives you’ve considered

I have considered encountering the errors myself manually and creating my own types, however I’m not aware of each of the errors

Additional context

No response

Is this something that you’d be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mkbctrlcommented, Nov 18, 2022

I ended up with a hook returning keyed object like that, here’s an example:

export const useAuthErrors = () => {
  const { t } = useTranslation('auth')

  const errorMap: Record<
    string,
    {
      message: string
      action: null | ((email?: string) => void)
    }
  > = {
    /** Thrown by amplify when email or password doesn't match */
    /** FIXME: The same exception is returned when you try to confirm already confirmed account */
    NotAuthorizedException: {
      message: t('validator.accountCredentialsInvalid'),
      action:() => {
        ...perform an action (optional) like a redirect or displaying toast
      },
    },
  }

  return {
    errorMap,
  }
}

This way I am able to translate the errors easily and control what will be displayed to the user + side effects

1reaction
wmoacommented, Nov 18, 2022

@joelzwarrington woops, I skimmed this thread in a rush (it’s been a long day), apologies.

That did the trick for now, thank you very much. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing error responses - Amazon Cognito
Amazon Cognito supports customizing error responses returned by user pools. Custom error responses are available for user creation and authentication, ...
Read more >
Common Errors - Amazon Cognito User Pools - 亚马逊云科技
This section lists the errors common to the API actions of all Amazon services. For errors specific to an API action for this...
Read more >
How to figure which is the right cognito error - Stack Overflow
How do you authenticate a user in a user pool via Cognito when error messages say userName and password don't match even though...
Read more >
Okta API Error Codes - Okta Developer
Okta error codes and descriptions. This document contains a complete list of all errors that the Okta API returns. All errors contain the...
Read more >
OAuth HTTP error response reference | Apigee Edge
On this page · Authorization Code. Invalid Redirect URI; No Redirect URI · Generate AccessToken. Invalid Auth Code · Implicit. Invalid Client ID...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found