Comments (12)
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 noredirectTo
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.
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.
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.
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.
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.
@ulasdemirci0 thanks for sharing your fix. If i go through this pain, will it fix the vercel deployment too?
from next.js.
@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.
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.
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.
@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.
Encountered the same problem, the rewrite method in next.config.js was abnormal
from next.js.
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)
- pnpm build does not detect @types/react nor @types/node even tho they're defined (vercel deploy)
- Your Team encountered an unknown problem. Please reach out to our support team for details. Learn More HOT 1
- server action transfrom incorrectly HOT 1
- Next/font does not work with Turbopack in a containerized development environment
- Each child in a list should have a unique "key" prop. No way to find the reason for it. HOT 1
- Docs(@next/eslint-plugin-next): not existing `.md` file for rule `no-typos`
- The RSC payload includes server data from all segments, including those from shared layout HOT 2
- Docs: Update Nextjs template for supabase HOT 1
- Next.js prod build logs errors twice HOT 4
- Next.js does not understand TypeScript project references
- Suspense always suspend HOT 4
- next/link has a incorrect prefetch, even though set the <Link prefeth={false} target="_selft" href="https://samedomain.com/path-b" /> HOT 2
- Hi @yaba101! With route interception, any soft navigation that matches the intercepted route will trigger the interception. However, you can make use of route groups with different layouts to have finer control over which layout renders the interception modal + page, versus just rendering the page, without changing your URL structure. You can learn a bit more about route groups [here](https://nextjs.org/docs/app/building-your-application/routing/route-groups). HOT 1
- Modal not closing after opening new page HOT 1
- Client components make bundle size huge
- Cannot read property 'startTime' of null on Android 9 with Chrome 74 HOT 1
- Cannot read property 'startTime' of null on Android 9 with Chrome 74 HOT 1
- Cannot read property 'startTime' of null on Android 9 with Chrome 74 HOT 1
- `useSearchParams` requires Suspense wrapper even when not exporting a component HOT 2
- It wont load i cant deploy websites or import them from github HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.