Next.js Dynamic Keys
- Category
- SDK
- Published
Keys and options passed to clerkMiddleware()
at runtime are available in Clerk’s server-side helpers.
![](/_next/image?url=%2F_next%2Fstatic%2Fmedia%2F_changelog%2F2024-07-16-dynamic-keys%2Fchangelog-dynamic-keys.png&w=3840&q=75&dpl=dpl_EvvyP6nWzCbeV2S4vavkeMBRBUvz)
Users building a multi-tenant application might need to provide different Clerk keys depending on the incoming request. Previously, you would need to pass these keys to all of Clerk’s Next.js server-side helpers. With Dynamic Keys support, keys passed to clerkMiddleware()
are made available to auth()
and other server-side helpers.
import { clerkMiddleware } from '@clerk/nextjs/server'
export default clerkMiddleware({
secretKey: '<YOUR_SECRET_KEY>',
publishableKey: '<YOUR_PUBLISHABLE_KEY>',
signInUrl: '/my-sign-in',
signUpUrl: '/my-sign-up',
})
export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
}
With a centralized place for passing server-side options, implementing a multi-tenant application that requires dynamic Clerk keys should be much more straightforward. This feature is available as of @clerk/nextjs@5.2.x
.
Check out the documentation for additional details and happy building!