Next.js server-side changes
Before starting this guide, please complete the Client-side changes.
API routes
Helpers for API routes have been updated to mirror the new useAuth()
hook on the client-side.
withSession
is deprecated and replaced withwithAuth
requireSession
is deprecated with replaced withrequireAuth
- Instead of decorating the
Request
object with aSession
object, it is now decorated with anAuth
object that mirrorsuseAuth()
on the client-side.const { userId, sessionId, getToken } = req.auth;
Example usage
import { withAuth } from "@clerk/nextjs/api"; export default withAuth(async (req, res) => { const { userId, sessionId, getToken } = req.auth; const hasuraToken = await getToken({template: "hasura"}); // Your handler });
Edge middleware
Edge middleware has also been updated to mirror the new useAuth()
hook on the client-side. The import path has also been changed to avoid confusion.
import { withEdgeMiddlewareAuth } from "@clerk/nextjs/edge-middleware"; export const middleware = withEdgeMiddlewareAuth((req, ev) => { const { userId, sessionId, getToken } = req.auth; // Your middleware });