nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Better error handling for `local` provider

Open simon-ccoms opened this issue 1 year ago • 4 comments

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
  • [X] Local
  • [ ] Refresh
  • [ ] New Provider

simon-ccoms avatar Dec 05 '24 14:12 simon-ccoms

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 avatar Dec 19 '24 14:12 phoenix-ru

Similar: #933

phoenix-ru avatar Dec 19 '24 17:12 phoenix-ru

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?

simon-ccoms avatar Jan 28 '25 16:01 simon-ccoms

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?

It does look correct

phoenix-ru avatar Feb 07 '25 15:02 phoenix-ru