Clerk logo

Clerk Docs

Ctrl + K
Go to


If you plan to use Next.js API routes or server-side rendering with getAuth, you must install withClerkMiddleware in your Next.js middleware. Otherwise, you can skip this step.

Copy this snippet into a file named middleware.js or middleware.ts in your project root.


For Middleware to run successfully, you need to include the CLERK_JWT_KEY in your environment variables.

Clerk only depends on the withClerkMiddleware() wrapper. You are welcome to customize the internal middleware function as needed.

Before Next.js 12.2

Using the withEdgeMiddlewareAuth wrapper you can access authentcation data


Example Response

More detailed information about the fields in this object can be found in the Authentication Object documentation.

Was this helpful?

Clerk © 2022