Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.dev

Middleware

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.

1
1
1

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

1

Example Response

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

Was this helpful?

Clerk © 2022