nextauthjs / nextauthjs/next-auth

Wrong URL after calling signIn function when using custom sign-in page

Open
#12,697 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Environment
"next": "15.1.7",
"next-auth": "^5.0.0-beta.25",
"react": "^19.0.0"

OS: Windows 10 Version 22H2 (OS Build 19045.5487)
Node.js version: v23.6.0
npm version: 11.1.0
Browser: Microsoft Edge Version 133.0.3065.82 (Official build) (64-bit) and Google Chrome
Reproduction URL

https://github.com/iltan987/redirect-issue

Describe the issue

First of all, this example is using custom sign in page.
As I understood, there are 2 ways to redirect user to sign-in page. Server-side and client-side. Using signIn function coming from the NextAuth instance in auth.ts (method 1 in my code) and using signIn function from "next-auth/react" (method 2)
The problem is when you use method 1, URL is not correct but rendered page is correct, just the URL wrong. You can see the correct URL only if you refresh the page manually.
Method 2 works completely fine; both URL seen in browser and rendered page are correct.

How to reproduce
  1. Run npm install
  2. Run npx auth secret or put your AUTH_SECRET to the .env file
  3. Run the app npm run dev
  4. In the main page, you will see 2 buttons. Press the one saying "Method 1", you will see wrong URL which includes "/api/auth/signin"
  5. Refresh the page (no need to do anything), and you will see the correct URL which is "/login"
  6. Go back to main page and press the other button. You will see that you will directly see the correct URL which is "/login"
Expected behavior

Same as method 2, without needing to refresh the page manually, URL in the browser should be same as the URL specified in NextAuth config

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with auth.ts and the two signIn call sites in the reproduction project, then run the documented npm install and npm run dev steps. Compare Method 1 with the next-auth/react Method 2 while using the custom sign-in configuration. Done means Method 1 updates the browser URL to /login without a manual refresh, matching Method 2 and the configured sign-in page.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.