-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
CallbackRouteError on Credentials when following docs #11074
Comments
For me, just returning null from |
i am facing the exact same issue |
I am not sure if its done intentionally but I went through the next-auth code and figured out that, even though CredentialsSignin error is being thrown, it is then passed to CallbackRouteError, which is why we are getting CallbackRouteError. here as you can see, catch recieves CredentialsSignin error. Since it is an instance of Error and not of AuthError, it skips the conditional, then rest is pretty much self explanatory. In order to solve this issue, if its an CredentialsSignin error, then instead of checking error.type === 'CredentialsSignin', what you can do is |
Experiencing the same issue as others: If I return null from authorize, it throws this error. This issue only started happening after upgrading to the latest beta. I went from |
thanks it worked |
When done this way, it will give the same error again if there is a connection problem with the database. |
@ondery what error are you getting? mind sharing the code snippets? |
The same issue with 5.0.0-beta.19 |
This comment has been minimized.
This comment has been minimized.
@bibaswan7 error.cause.err.code === 'credentials' will give true in case of database connection problems too unfortunately. |
@bibaswan7 I came to the same conclusion, but since I'm using typescript, it screams at me saying that property of code does not exist on type Error. Does anyone know a way to do typing properly with this weird wrapping, as well as @ondery mentioned, a way to disambiguate this error further? I looked into the typing issue a bit more and found commit |
I think I have a fix of just signing in and handling an error if the password is incorrect. Instead of using signIn() function from the @/auth.js file we can do somthing like this in the signinForm:
If the signIn() functions throws an error Then it means that The credentials are invalid...
|
Yeah @Ali-Raza764 That's exactly what I do currently, but I just want a bit more fine grain control over the error, and it is supposed to work, but just doesn't. For example, what if my API endpoint became unreachable and just timed out.. It would still say to check the credentials on the client side, even if they are correct. That would lead the user to try a bunch of times and then try to reset the password, which is not something I would want. Instead I want to distinguish whether it's because of the credentials (user does not exist on the token in the Callback). I think this could just be fixed with the typing, as @bibaswan7 said. The issue for the broken types is #11155. The types are broken in #11050 |
Ok I do understand that. So we can wait until the new release makes a fix ? |
This comment has been minimized.
This comment has been minimized.
In case it's helpful, can confirm that Credentials-based error handling broke for me when switching to from Errors previously classified |
I rolled back from 5.0.0-beta.19 to 5.0.0-beta.18 and it worked for me. Clearly its a bug on 5.0.0-beta.19 so until a new update comes I ll stick to the previous version |
Yeah, downgrading fixed the issue for me too |
Exactly same issue as OP, downgrading to beta.18 didn't work
|
use edit: I forgot to add yarn for yarn users. my bad |
So which version of the code is working for you now?? Can you show an example how you got the custom errors? |
I am facing a similar issue with @auth/core:0.31.0 and @auth/sveltekit:1.1.0. The response object for signIn is always returning no error when user submits invalid credentials. |
this fixed it for me, thanks. |
Tried again a week later with the same code and Also don't throw any other errors except so either |
downgrading from "next-auth": "^5.0.0-beta.19" to 18 allows a custom error responses to throw and be handled in the client. Can't understand abstracting this away from the developer 😕, at least default it to off and allow us to specify an process env var to enable throwing custom core authorize errors and any auth life cycle hook. |
thanks that is work well now |
"next": "14.2.4", |
just downgrade to To fix it first remove next-auth from package json then run npm i then install
inside of the login function
i hope this helps |
Provider type
Credentials
Environment
Reproduction URL
https://github.com/theswampire/authjs-bug-reproduction
Describe the issue
When using the Credentials Provider, submitting a wrong password throws an CallbackRouteError. I tested it on 5.0.0-beta.18, 17 and 16 too but they throw CredentialsSignIn instead.
I followed the v5 docs for setting up Nextjs and the Credentials Provider step by step thus this should be unexpected behaviour.
This is the
auth.ts
file:The SignIn page looks like this:
I tried to wrap the signIn call in a try-catch like in #11010 but that obviously didn't fix the underlying issue.
According to the documentation, the CallbackRouteError using the Credentials Provider means that either the
authorize
or another callback throws but I didn't overwrite any callbacks nor shouldauthorize
throw anything. Furthermore, if I remember correctly, when settingredirect
to false, theSignInResponse
containedok: true
and a Configuration error which I find odd.How to reproduce
Enter anything but the correct password "password" and then the exception should be thrown.
Using the correct password works just fine.
Expected behavior
Don't throw an exception.
The text was updated successfully, but these errors were encountered: