-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[v5] Throwing error with custom sign in page leads to undefined route #11008
Comments
Thanks for opening! 👏 |
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008
I am working on an application using a credentials provider. When I throw an error in the authorize method, I see similar behavior. onClick={() =>
signIn("signin", {
username,
password,
redirect: false,
}).then((res) => {
if (res?.ok) {
void router.push("/dashboard");
} else {
if (res?.error) {
setSignInError(
res.error || "There was an error signing in",
);
setPassword("");
}
}
})
} This is the javascript code I am calling. However, when the promise returns after I throw an error for invalid credentials, this is the object I get:
This is the error I am throwing: authorize: async (credentials) => {
if (!credentials) {
throw new Error("Invalid credentials");
}
const creds = await db.credentials.findFirst({
where: {
username: credentials.username as string,
},
});
if (!creds) {
throw new Error("Invalid credentials");
} I would expect the "ok" field to be false and the "error" field to be the error I threw. |
As far as I understand what
I think you should check in your case |
Same error when i deploy this project: https://github.com/vercel/nextjs-postgres-auth-starter |
…rows an error (#11010) * Fix NextAuth redirecting to /undefined when signIn method throws an error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: #11008 * Move action test to tests folder * Remove test-adapter and add reference to docs * Defend from undefined responseUrl * Fix linter * chore(test): simplify tests --------- Co-authored-by: Thang Vu <hi@thvu.dev>
How do you figure it returns the URL only? As per the docs you linked, this is the return type:
This hasn't changed as far as I'm aware from previous version. The "ok" field on the return object should be false and the error should be the error message thrown in the authorize method on the credentials provider. In my example, error was not the correct string and "ok" was true even though an error was thrown. |
…rows an error (nextauthjs#11010) * Fix NextAuth redirecting to /undefined when signIn method throws an error @auth/core `Auth` function can return an internalResponse or a Standard Response. Internal response has a `redirect` attribute. The problem is that the logic inside `Auth` method when there is an error is returning a Standard web Response which doesn't have `redirect` attribute but we can get redirecting url by using `headers.get('Origin')`. I think this fix this issue: nextauthjs#11008 * Move action test to tests folder * Remove test-adapter and add reference to docs * Defend from undefined responseUrl * Fix linter * chore(test): simplify tests --------- Co-authored-by: Thang Vu <hi@thvu.dev>
Environment
Reproduction URL
https://github.com/peguerosdc/nextauth-bug-error-undefined
Describe the issue
When logging in via Magic Links using Resend, a custom
sendVerificationRequest
(following this official guide) and NOT using a custom sign in page, if I throw an error insidesendVerificationRequest
like this:I am redirected to a default Error page with a configuration error in the search params:
/api/auth/error?error=Configuration
.But when I use a custom login page like this:
And I throw the error, I am redirected to
/auth/undefined/
.Moreover, when other kind of errors are thrown, I am redirected to my
/auth/signin?error=ErrorType
page WITH theerror
search param indicating what happened.How to reproduce
/auth/undefined/
./auth.ts
, remove the custom pages configuration and repeat steps 3-5 to see how you are redirected to/api/auth/error?error=Configuration
Expected behavior
I would expect:
/auth/undefined/
(being the/auth/signin?error=ErrorType
approach my preferred one as I don't have to create a whole new page just to show an error and a button that would redirect me again to thesign in
page)The text was updated successfully, but these errors were encountered: