Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthApiError "Invalid login credentials" has undefined code #937

Closed
2 tasks done
peterkos opened this issue Aug 2, 2024 · 3 comments
Closed
2 tasks done

AuthApiError "Invalid login credentials" has undefined code #937

peterkos opened this issue Aug 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@peterkos
Copy link

peterkos commented Aug 2, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When attempting to login a user with invalid credentials, the returned error is missing a code:

const { data, error } = await supabase.auth.signInWithPassword({
  email: loginDto.email,
  password: loginDto.password,
});
if (isAuthApiError(error)) {
  if (error.code == 'user_not_found') {
    throw new UnauthorizedException();
  } else {
    throw new InternalServerErrorException(
      `Unhandled Supabase auth error code: ${error}`, // <-- error.code undefined
    );
  }
} else { /* ... */ }

Output:

Unhandled exception: {
  "statusCode": 500,
  "message": "Unhandled Supabase auth error code: AuthApiError: Invalid login credentials",
  "error": "Internal Server Error"
}

The source of AuthAPIError has code as undefined:

export class AuthInvalidCredentialsError extends CustomAuthError {
constructor(message: string) {
super(message, 'AuthInvalidCredentialsError', 400, undefined)
}
}

To Reproduce

  1. Perform supabase.auth.signInWithPassword({ /* ... */ }) with incorrect credentials
  2. Observe error.code is undefined

Expected behavior

Per docs:

Use isAuthApiError instead of instanceof checks to see if an error you caught is of this type.

Do not use string matching on error messages! Always use the name and code properties of error objects to identify the situation.

code should be defined for an AuthApiError.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS
  • Version of supabase-js: 2.45.0
  • Version of Node.js: v21.7.3
@peterkos peterkos added the bug Something isn't working label Aug 2, 2024
@peterkos peterkos changed the title "Invalid login credentials" has undefined code AuthApiError "Invalid login credentials" has undefined code Aug 2, 2024
@peterkos
Copy link
Author

peterkos commented Aug 2, 2024

It looks like this is also here: supabase/auth#1631

I figured this issue was JS-specific, but it appears not?

@peterkos
Copy link
Author

peterkos commented Aug 2, 2024

My workaround:

if (isAuthApiError(error)) {
  if (error.code == 'user_not_found') {
    throw new UnauthorizedException();
  } else {
    throw new UnauthorizedException(`${error}`);
  }
} else if (error) {
  throw new InternalServerErrorException(
    `Unhandled unknown error: ${error}`,
  );
}

@J0
Copy link
Contributor

J0 commented Aug 27, 2024

Hey,

Thanks for flagging the issue. A fix has been merged and this should be patched later this week or early next week with our next deploy

Hope this helps. I'm going to close for now but feel free to re-open or head to #804 if there are any issues after upgrading. You can track the version under Settings > Infrastructure > Service Versions > Auth version. Should be good to go once your project version is v2.159.0 or later

@J0 J0 closed this as completed Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants