Skip to content

Issue with signIn('credentials') inside a Next.js Route Handler #12900

Answered by jeslor
abgonzalez93 asked this question in Help
Discussion options

You must be logged in to vote

You appear to be attempting to call signIn('credentials') inside a Next.js API route (or in a custom backend handler), but neither a session nor cookies are being created, and instead of returning an object with { ok, error } as you would anticipate from a server-side function, it is returning a URL string (such as http://localhost:3000/). This most likely happens because you are using signIn() in a non-client context (such as an API route), and NextAuth's behavior is designed to handle redirects rather than directly manage server-side sessions.

Here are the key issues;

  • signIn() in NextAuth is not intended to be used in API routes directly for programmatic login.
  • signIn() is designed for…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@ValentinGurkov
Comment options

@abgonzalez93
Comment options

@abgonzalez93
Comment options

Comment options

You must be logged in to vote
2 replies
@abgonzalez93
Comment options

@jeslor
Comment options

Answer selected by abgonzalez93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants