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

Better error handling for local provider #952

Open
1 of 5 tasks
simon-ccoms opened this issue Dec 5, 2024 · 3 comments
Open
1 of 5 tasks

Better error handling for local provider #952

simon-ccoms opened this issue Dec 5, 2024 · 3 comments
Labels
enhancement An improvement that needs to be added p3 Minor issue

Comments

@simon-ccoms
Copy link

Describe the feature

There is no documentation on how to handle errors from external APIs when signing in using the local provider.

How would you implement this?

The only way I've managed to implement this is to use the following code. I'm not sure if there's any other way.

try {
    await signIn(
      {email: values.email, password: values.password},
      {callbackUrl: "/"}
    );
  } catch (error) {
    setFieldError("password", error?.response._data.detail);
    setErrors(error?.response._data);
  }

Additional information

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider
@simon-ccoms simon-ccoms added enhancement An improvement that needs to be added pending An issue waiting for triage labels Dec 5, 2024
@phoenix-ru phoenix-ru added p1 Low priority p3 Minor issue and removed pending An issue waiting for triage p1 Low priority labels Dec 19, 2024
@phoenix-ru
Copy link
Collaborator

I don't think there's a guide on how to handle errors produced by our module. I can see the importance of it, however, support for errors is not there yet.

What information would you like to get out of the error? I am slowly starting to introduce typed errors to our module, so your input will be valuable

@phoenix-ru
Copy link
Collaborator

Similar: #933

@phoenix-ru phoenix-ru changed the title Explain how to handle errors from external API when signing in Better error handling for local provider Dec 19, 2024
@simon-ccoms
Copy link
Author

The issue here is that when I submit my login form with an invalid username using the signIn() method, the external API responds with a 401 (Unauthorised). Unless I wrap the call in a try/catch and set the error in my form based on what comes back in the response as above, the page gives me no feedback as to what happened.

So I guess the question is, is my code above the correct way of going about this? Or should I be doing it some other way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement that needs to be added p3 Minor issue
Projects
None yet
Development

No branches or pull requests

2 participants