3 ms·
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.j
by charcircuit 3y ago
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.
- xyzzy4747 3y agoYou 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.
- warent 3y agoExcept 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
- xyzzy4747 3y agoAh, I see. That’s very annoying.
- williamstein 3y agoTo 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/routing https://nextjs.org/docs/app/building-your-application/routin...
- charcircuit 3y agoYes, 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.
- joshgermon 3y agoYeah 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.
- phryneas 3y agoYou can just call the `cookies()` or `headers()` function in every server component in the app router?
- dbbk 3y ago> Except getServerSideProps is no longer used in Next 13 Yes it is?
- bobx11 3y agoFwiw, iron session is working ok on client and ssr for me.
- uhryks 3y agoAgree, 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)