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