Skip to content

URL Not Updating After Login in NextAuth.js v5 (Next.js 15, React 19) #12711

@hashirshoaeb

Description

@hashirshoaeb

Environment

  System:
    OS: macOS 15.3.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 79.27 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.5.0 - ~/.nvm/versions/node/v23.5.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v23.5.0/bin/npm
  Browsers:
    Chrome: 133.0.6943.55
    Safari: 18.3
  npmPackages:
    next: 15.1.2 => 15.1.2 
    next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25 
    react: 19.0.0 => 19.0.0 

Reproduction URL

https://github.com/hashirshoaeb/next-auth-test-app

Describe the issue

I’m experiencing an issue where the page visually updates after login, but the URL remains stuck on /login. Additionally, signing out does not work unless the page is manually refreshed. It started happening after upgrading Next.js, NextAuth.js, and React to the latest versions.

Previously Working Setup:

"dev": "next dev",
node: 18
"next": "^14.0.3",
"next-auth": "^5.0.0-beta.13",
"react": "18.2.0",

Updated Setup (Causing Issue):

"dev": "next dev --turbopack",
node: 22
"next": "15.1.2",
"next-auth": "^5.0.0-beta.25",
"react": "19.0.0",

#12697 looks similar issue.

How to reproduce

Steps to Reproduce:

  1. use the example link from Reproduction URL
  2. Run npm install
  3. Run npx auth secret or put your AUTH_SECRET to the .env file
  4. Run the app npm run dev
  5. Visit /login and sign in.
  6. The page visually changes to the home page, but the URL remains stuck at /login.
  7. Clicking “Sign Out” at this point does nothing.
  8. Manually refreshing the page updates the URL correctly to /, and the sign-out button starts working.

I have recorded a demo video to explain the issue.

Screen.Recording.2025-02-27.at.12.07.31.AM.mov

Expected behavior

  • After logging in, the URL should update correctly to / without requiring a manual refresh.
  • The sign-out button should function properly without needing a hard refresh.

Activity

added
bugSomething isn't working
triageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
on Feb 26, 2025
Coding-faizan

Coding-faizan commented on Feb 26, 2025

@Coding-faizan
benhovinga

benhovinga commented on Mar 4, 2025

@benhovinga
Contributor

@hashirshoaeb When using the signIn() function you need to add redirectTo to it's options.

In your file actions/auth.actions.ts file update the signIn() options.

    await signIn("credentials", {
      email: formData.get("email") as string,
      password: formData.get("password") as string,
      redirect: true,
      redirectTo: "/"    // <-- Add this
    });
hashirshoaeb

hashirshoaeb commented on Mar 6, 2025

@hashirshoaeb
Author

@hashirshoaeb When using the signIn() function you need to add redirectTo to it's options.

In your file actions/auth.actions.ts file update the signIn() options.

await signIn("credentials", {
  email: formData.get("email") as string,
  password: formData.get("password") as string,
  redirect: true,
  redirectTo: "/"    // <-- Add this
});

Thanks, it worked. Do you know how can I redirect to callback url then?

benhovinga

benhovinga commented on Mar 6, 2025

@benhovinga
Contributor

Do you know how can I redirect to callback url then?

@hashirshoaeb I am not sure what you mean by this. Typically the authenticating server (such as Google or Github) will reply to the callback URL with the authentication result. You typically don't send the user there.

Are you attempting to redirect the user to the page they were on before going to the login page? For that you would need to know where the user was prior to redirecting to the login page and pass that along such as in the searchParam https://app.com/login?redirect=%2Fprofile.

azr-arch

azr-arch commented on Mar 21, 2025

@azr-arch

I'm experiencing the same issue, but I couldn't simply specify the redirect URL.

what I mean is that the application I'm working on includes both a normal user and an admin side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @benhovinga@hashirshoaeb@Coding-faizan@azr-arch

        Issue actions

          URL Not Updating After Login in NextAuth.js v5 (Next.js 15, React 19) · Issue #12711 · nextauthjs/next-auth