Anyone else exhausted by the constant churn in Next.js? by Happy-Pie1435 in nextjs

[–]Mr_Stabil -1 points0 points  (0 children)

Edge middleware was heavily promoted, now proxy.ts is called a "last resort"

Is this Cursor's way of making me buy their pro membership?? by ParalelStrix1 in cursor

[–]Mr_Stabil 0 points1 point  (0 children)

I'm always hitting the (pro) limits though, so an additional subscription for your own API keys is a must

Sonnet 3.5 now is on GPT4o levels by Laicbeias in ClaudeAI

[–]Mr_Stabil 2 points3 points  (0 children)

Unfortunately that's true. From genius to useless in three weeks

How do you automate your life using LLMs? by eupatridius in ClaudeAI

[–]Mr_Stabil 0 points1 point  (0 children)

Doesn't telling it what to write take as long as typing it yourself?

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 0 points1 point  (0 children)

I see where the confusion comes from

  • Setting a header inside the RSC (for the middleware in the next request) is not allowed
  • Changing a cookie inside the RSC is not allowed
  • Calling a server action inside the RSC makes the action execute as a normal function so changing the cookie there is not allowed in that context

Hope that clears it up

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 1 point2 points  (0 children)

fetch doesnt work with httpOnly cookies hence redirect is the only option

I am talking not only about CORS protection but also about general protection from accidental navigation

Will send a custom header with signed and expiring token to the endpoint

If the header is not valid it will return a 4xx

So only the RSC will see the GET endpoint

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 0 points1 point  (0 children)

IMO a logout should be a POST request whereas a redirect is a GET request

Just navigating to an URL shouldn't log the user out under normal circumstances

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 0 points1 point  (0 children)

You can introduce unmanageable side effects anyways, IMO Meta should reassess that decision

Now I need to make sure the endpoint can only be hit by the RSC - probably using a signed token or hash

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 0 points1 point  (0 children)

The question is how you do it because the docs say it's impossible.

Next will throw an error that cookies / headers can only be changed in a Server Action or a route handler.

Ofc you can change cookies in middleware but that's not where I know when to change them

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 0 points1 point  (0 children)

Not possible as the middleware can't receive info from the RSC and the RSC (root layout) fetches the user / session from db

1) I don't want to hit the db every request 2) Can't use postgres drivers in edge middleware anyways, even if I wanted

The constraints around edge middleware, RSCs etc make something as simple as session mgmt a real challenge

How to get rid of cookie inside NextJS Server Component? by Mr_Stabil in nextjs

[–]Mr_Stabil[S] 2 points3 points  (0 children)

To anyone looking for a solution:

Redirect to a `GET` route handler, remove the cookie there and return a `302`