

























Version 4.5 of @clerk/nextjs brings sweeping improvements to server-side authentication in Next.js.
Get started with npm i @clerk/nextjs@latest
Going forward, developers will authenticate requests once in Next.js middleware, then simply read the authentication state in endpoints (API routes and getServerSideProps).
middleware.js example:
API routes example:
getServerSideProps example:
With this change, authentication in Next.js will finally feel familiar for developers who have worked with frameworks like Express or Ruby on Rails, where authentication is normally handled within middleware.
Next.js 12.2 brought a switchable runtime, so developers could choose between a node runtime or an edge runtime for each of their API routes and server-rendered pages.
Our new getAuth() helper is isomorphic, so it works regardless of the runtime you choose.
If you've used Clerk in the past, you'll notice three small but delightful improvements to our developer experience:
Our team has been watching the Next.js Layouts RFC closely, and we designed the new helpers in anticipation of layouts support.
We expect that by computing the authentication state in middleware, we'll be able to share it with each of your parallel-loading layout files.
Get started right away with our guide to Next.js authentication, or join our community Discord to discuss with our team.
Thanks to the contributors: Mark Pitsilos, Nikos Douvlis
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。