Code Monkey home page Code Monkey logo

Comments (12)

ztanner avatar ztanner commented on July 22, 2024 3

Hi @ameer-clara --

Upon closer inspection of the reproduction, it seems like next-auth is conflicting with your middleware redirect.

I was able to get it to work by updating your signIn and signOut methods as follows:

export async function login(prevState: any, formData: FormData) {
  // ...existing code
  await signIn('credentials', { redirectTo: '/protected', email, password })
  // ...existing code
}
export async function logout() {
  await signOut({ redirectTo: '/' })
}

Here's what's happening:

  • you submit the sign in form
  • the signIn server action from next-auth is redirecting to / by default when no redirectTo is specified (source)
  • importantly: at this point, the router has already received a response from the server, indicating it's on the / page.
  • Next.js will fire off an intra-app request to / since that's what the redirect told it to do, but because the user is now authenticated, your middleware signaled it to instead forward the request to /protected
  • The signIn request to / returns the page data for /protected, hence the UI updating, but not the URL.

I think the right way to fix this is to prevent next-auth from redirecting the server action handler to the / page, as your intended behavior is to redirect to /protected.

I'm going to close this issue as I believe this is behaving as expected, and will separately look into the other linked issues in this thread, as I suspect they're different.

from next.js.

ztanner avatar ztanner commented on July 22, 2024 1

Thanks for your prompt response and posting the video. That is the expected behavior. The issue occurs when you update to release >14.1.2.

bug.mov

See attached video of the reproduction and fix when reverted to an earlier version.

Sorry, I didn’t realize the repro was pinned to the working version. We’ll take a look!

from next.js.

ztanner avatar ztanner commented on July 22, 2024

Hi @ameer-clara -- I cannot reproduce the issue you're describing. Here's a video of me running your reproduction below.

CleanShot.2024-05-18.at.12.28.10.mp4

Your reproduction also doesn't make use of interception routes. Did you provide the correct link?

Have you tried clearing your .next folder? What browser are you using?

from next.js.

ameer-clara avatar ameer-clara commented on July 22, 2024

Thanks for your prompt response and posting the video. That is the expected behavior. The issue occurs when you update to release >14.1.2.

bug.mov

See attached video of the reproduction and fix when reverted to an earlier version.

from next.js.

ulasdemirci0 avatar ulasdemirci0 commented on July 22, 2024

The issue was related to update procedure.
I resolved it by moving my src folder to a freshly installed Next.js project and manually adding my other node modules using pnpm add.

Surprisingly, this fixed the problem.

You can use same procedure for your project, then manually add required modules and move your src folder completely.

And never use again pnpm update or npm update..

from next.js.

ameer-clara avatar ameer-clara commented on July 22, 2024

@ulasdemirci0 thanks for sharing your fix. If i go through this pain, will it fix the vercel deployment too?

from next.js.

ulasdemirci0 avatar ulasdemirci0 commented on July 22, 2024

@ulasdemirci0 thanks for sharing your fix. If i go through this pain, will it fix the vercel deployment too?

I don't have a clue, my project still in development stage on localhost...

But it's the only decent fix I found since 3 days.

Even you delete everything and just install from fresh package.json doesn't work. I moved my source to fresh installed nextjs.

It's really weird bug also I found other issues on github this bug didn't solved since nextjs 12

from next.js.

ulasdemirci0 avatar ulasdemirci0 commented on July 22, 2024

I guess i found the main reason of this bug...

If you delete layout.tsx at root of your project nested layouts works but redirect function doesn't.

from next.js.

zaru avatar zaru commented on July 22, 2024

I am experiencing the same issue. My reproduction code works fine with version 14.1.3, but Parallel Routes do not function correctly in version 14.2.2.

Here is the sample repository:
https://github.com/zaru/nextjs-parallel-routes-issue-65936

2024-05-20.10.34.41.mov

same issue: #65411

from next.js.

ameer-clara avatar ameer-clara commented on July 22, 2024

@ztanner Appreciate your super fast turnaround on this and for your detailed message and explanation. Your fix works, however, i also see a 303 in the logs as well as the root url not updating. I will post an updated repo and video to highlight the problem. Thanks again

from next.js.

CrewS avatar CrewS commented on July 22, 2024

Encountered the same problem, the rewrite method in next.config.js was abnormal

from next.js.

github-actions avatar github-actions commented on July 22, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.