Back

Engineering


Oct 04, 2022

Back

Engineering


Oct 04, 2022

@clerk/nextjs v4.5

Colin Sidoti

Colin Sidoti


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

Authentication moves to middleware

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.

Switchable runtime support

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.

Improved developer experience

If you've used Clerk in the past, you'll notice three small but delightful improvements to our developer experience:

  1. All server-side imports are now from @clerk/nextjs/server instead of having import paths specific to the endpoint-type
  2. Wrapper functions are no longer required inside endpoints, only once in middleware
  3. getAuth(req) works everywhere there's a request object
1

Preparation for Layouts

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

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 and Nikos Douvlis
Mark Pitsilos
Nikos Douvlis

Suggested reading

Introducing Web3 Authentication

Engineering

Introducing Web3 Authentication

Clerk is saving Web3 developers from the greatest evils of the Web2 platform: cookies, multifactor authentication, and profile enrichment

Colin Sidoti

Colin Sidoti


Jan 21, 2022

Clerk's logo

Start Now,
No Strings Attached

Start completely free for up to 5,000 monthly active users and up to 10 monthly active orgs. No credit card required.

Start building

Pricing built for

businesses of all sizes.

Learn more about our transparent per-user costs to estimate how much your company could save by implementing Clerk.

View pricing
Clerk's logo

Newsletter!

The latest news and updates from Clerk, sent to your inbox.

Clerk logo

Clerk - Complete User Management

TwitterLinkedInGitHubDiscordFacebook

© 2022 Clerk Inc.


product
Features

© 2022 Clerk Inc.