fix(frontend): await auth() in clerkMiddleware callback

This commit is contained in:
Kunal
2026-02-07 20:43:14 +00:00
parent 7b4c40ae0b
commit 0fe9d8f79a

View File

@@ -12,12 +12,11 @@ const isClerkEnabled = () =>
const isPublicRoute = createRouteMatcher(["/sign-in(.*)"]);
export default isClerkEnabled()
? clerkMiddleware((auth, req) => {
? clerkMiddleware(async (auth, req) => {
if (isPublicRoute(req)) return NextResponse.next();
// Clerk typings in App Router return SessionAuthWithRedirect.
// Use redirectToSignIn() instead of protect(). Keep middleware callback sync.
const { userId, redirectToSignIn } = auth();
// Clerk typings in App Router return a Promise; keep middleware callback async.
const { userId, redirectToSignIn } = await auth();
if (!userId) {
return redirectToSignIn({ returnBackUrl: req.url });
}