auth: Adding error codes to ApiError

Feature request

Is your feature request related to a problem? Please describe.

I am building a website with supabase and the errors that is returned from supabase.auth only contains a general error code 400 and a message in english. This makes the different errors hard to distinguish from eachother.

Example: User tries to create an account but the user is already registered so the error returned from supabase.auth.signUp will be

{ 
  message: "User already registered",
  status: 400
}

Describe the solution you’d like

If the error included a specific error code mapped to particular error then providing a custom message would be easy.

Example:

{ 
  message: "User already registered",
  status: 400,
  errorCode: 1,
}

It would also be really awesome if the error codes was included in the documentation.

Describe alternatives you’ve considered

I’ve considered checking the string value returned in the error but if that would change in the future that would in turn break the application.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 96
  • Comments: 38

Most upvoted comments

+1 for this change, as at this time distinguishing between errors (and translating them to different languages), is completely contingent on parsing the message being returned (and if that message one day got changed, it would break whatever logic we’ve had to build on top of it)

I ran into the same issue and started collecting possible error messages by going through the GoTrue implementation.

I collect the errors for each endpoint in this Google Sheets doc. It’s WIP so everything in this sheet is a little bit messy at the moment.

I also created a npm package that offers an error handler method for each function of GoTrue JS and therefore also Supabase JS.

Over a year later and this has not been addressed. I thought features like this were standard practice.

Such improvement would be great for developer experience, +1 to this idea.

I strongly support this request!
Error codes would facilitate the creation of dictionary data for translation and help with multilingualization.

I am developing an application for Japanese and currently there is no list of error messages, so I am having a hard time creating dictionary data.

+1, Firebase has these standard error codes and it really is essential if you want to, for example, translate the messages

Any progress on this would be great help! Is there a way we can contribute ourselves?

@SamiChab @262hz Looks like the PR for this has been merged just recently:

https://github.com/supabase/gotrue/pull/1377

I believe it’s in a release candidate at the moment.

This just made ditch supabase Auth for something else.

Its standard practise to return proper errors.

But till now over a year nothing has been done. There is no proper CURL documentation for us to implement the rest Auth into a SDK ourselves.

Even on the little examples, errors are not treated well. this is a no no for me,shows an unserious company in this aspect

Thought this was industry standard and not something to implement upon request. Any developments on this?

Related to supabase/supabase#12739

Since supabase doesnt offer such feature, I build my own npm package. It is my own npm package. It can be used to translate auth, storage, realtime and database errors into 8 languages. Might be worth checking out

https://www.npmjs.com/package/supabase-error-translator-js?activeTab=readme

no news on this? how people are handling authentication errors and internalization?

@Erybor I will try and get this added into the Python library by next week. Yeah the error codes got added to the Python docs before I was able to add the codes into the library. I’ve added an issue to track this in the Python library https://github.com/supabase-community/auth-py/issues/554

@Erybor That’s not surprising, looks like the Python library isn’t maintained by Supabase:

image

You probably want to go open an issue or PR in the repo to add support:

https://github.com/supabase-community/supabase-py

@Erybor This has been implemented (see https://supabase.com/docs/reference/javascript/auth-error-codes), but it’s looks like there might be a bug for the “invalid login credentials” case?

For example, if I use the supabase.auth.admin.generateLink() function with an email address not in the database, I get this error (notice the code):

{
  data: { properties: null, user: null },
  error: AuthApiError: User with this email not found
      « stack trace » {
    __isAuthError: true,
    status: 404,
    code: 'user_not_found'
  }
}

However, if I try to log in (supabase.auth.signInWithPassword()) with invalid credentials I get this error back (missing a code):

{
  data: { user: null, session: null },
  error: AuthApiError: Invalid login credentials
      « stack trace » {
    __isAuthError: true,
    status: 400,
    code: undefined
  }
}

The docs pretty clearly state there should always be a code:

Errors originating from the server API classed as AuthApiError always have a code property that can be used to identify the error returned by the server.

@mashwishi I’d say you hit that exact same bug here: https://github.com/supabase/auth/pull/1377#issuecomment-2027954397

I’ve created a new issue to track that bug:

https://github.com/supabase/auth-js/issues/947

@kangmingtay I think this issue should be closed to avoid confusion about the status of this feature.

How is this extremely basic and necessary feature still not implemented after more than 2 years???

That’s why i stopped using supabase…

How is this extremely basic and necessary feature still not implemented after more than 2 years???

It was already merged but i think its’s for auth-js only is it different from supabase-js using supabase.auth?

is this only for auth-js ? and supabase-js not included?

            const response = await supabase.auth.signInWithPassword({
                email: email,
                password: password,
            })

image Version: "@supabase/supabase-js": "^2.41.1"

It’s been two years and still no update?

Over a year later and this has not been addressed. I thought features like this were standard practice.

They have been busy with the unusable AI bs.

+1, it’s hard to use registration/signin manually with react native development using supabase lib, i am a js/ts library user but i would recommend having code status too…

I have already created feature request since Sept but no one have ever response to it

@haydn I’m using the Python client (latest version 2.5.3), went through the full source code and there’s no “code” in AuthApiError. Only “name”, “message” and “status”. So I’m forced to check for the strings in messages which is very frustrating.

I think the Python documentation just has the JavaScript docs copy and pasted: https://supabase.com/docs/reference/python/auth-error-codes.

Running into the same issue – would love to have standardized error codes for auth (I’m using supabase.auth.signInWithOtp() specifically). Firebase has a doc about this: https://firebase.google.com/docs/reference/js/v8/firebase.auth.Error