fix(frontend): await auth() in clerkMiddleware callback
This commit is contained in:
@@ -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 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user