News for hackers. Stuff that matters.
Re:Next.js App Router Update by charcircuit on Thursday June 22, 2023 @08:23PM (#36441109)
I gave up on Next.js because of it's architecture. It does not support normal authentication use cases via cookies eg. include the logged in user's name. Next.js wants to prerender a page such that any user can be served it. This means that your first paint will always be incomplete since you have to fill in all the user specific stuff client side.

I ended up migrating to Remix and my application was easy to build how I wanted with cookies. Next.js API for working with cookies wasn't that good either.

Unfortunately, this update did not include anything to address this. Next.js seems fine to use if you are making a landing page or some site which does not require authentication, but I wouldn't use it for anything complex.

Re:Next.js App Router Update by xyzzy4747 on Thursday June 22, 2023 @08:31PM (#36441175)
You can use getServerSideProps to look at the cookies before rendering the page for a user.

It’s slightly annoying though since you can’t use both getServerSideProps and getStaticProps on the same page.

Re:Next.js App Router Update by warent on Thursday June 22, 2023 @08:35PM (#36441198)
Except getServerSideProps is no longer used in Next 13 and actually you have no simple access to the request object anymore. Have to write middleware for everything, it is extremely frustrating
Re:Next.js App Router Update by xyzzy4747 on Thursday June 22, 2023 @08:46PM (#36441283)
Ah, I see. That’s very annoying.
Re:Next.js App Router Update by williamstein on Thursday June 22, 2023 @08:47PM (#36441291)
To clarify -- using getServerSideProps works for routes defined in the pages/ directory in Next 13, but not for routes defined in the app/ directory. Both pages and app are still fully supported in Next 13. See https://nextjs.org/docs/app/building-your-application/routin...
Re:Next.js App Router Update by charcircuit on Thursday June 22, 2023 @09:11PM (#36441502)
Yes, I tried making a middleware for auth, but it just was not working for me. I think I had trouble passing along information to the actual page or something. I also was unable to have my login page handle authentication to set the cookie so I had to do go and make an API for it. I eventually cut my losses and gave up since it felt like my app was going against the grain.
Re:Next.js App Router Update by joshgermon on Thursday June 22, 2023 @11:47PM (#36442544)
Yeah which honestly I don't mind the middleware approach for authentication although the route matching is pretty bad for fine grain control.

However another thing is the middleware is all through the edge runtime. So things like regular postgres drivers don't work (although I did hear that Cloudflare workers added TCP so maybe that's coming).

I will say Planetscale and the hottest db as a service platforms all seem to have an edge adapter to allow for this but your SOL otherwise.

Re:Next.js App Router Update by phryneas on Friday June 23, 2023 @04:14AM (#36444157)
You can just call the `cookies()` or `headers()` function in every server component in the app router?
Re:Next.js App Router Update by dbbk on Friday June 23, 2023 @08:24AM (#36445867)
> Except getServerSideProps is no longer used in Next 13

Yes it is?

Re:Next.js App Router Update by bobx11 on Thursday June 22, 2023 @08:51PM (#36441314)
Fwiw, iron session is working ok on client and ssr for me.
Re:Next.js App Router Update by uhryks on Thursday June 22, 2023 @09:49PM (#36441838)
Agree, it's like they made no effort to make hydration easier. Even the router doesn't have the route info on the first render on the client, I had to pass it with getServerSideProps, that's ridiculous.

If you have to re-engineer all your code to avoid content shift, why bother using a mega-framework like Next in the first place? Also the point of SSR and hydration is to improve performance and page loads, if you have a ton of work to do again on the client that's very small actual performance gains, but that's not so much of a surprise considering Next is one of the heaviest frameworks out there (in bundle size)