Oct 04, 2022
Oct 04, 2022
New in 4.5: Authentication moves to middleware, switchable runtime support, improved developer experience, preparation for Layouts
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).
API routes 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.
Start completely free for up to 5,000 monthly active users and up to 10 monthly active orgs. No credit card required.
Learn more about our transparent per-user costs to estimate how much your company could save by implementing Clerk.
The latest news and updates from Clerk, sent to your inbox.