-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
23 lines (18 loc) · 819 Bytes
/
Copy pathproxy.js
File metadata and controls
23 lines (18 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
const isPublicRoute = createRouteMatcher(["/", "/sign-in(.*)", "/sign-up(.*)", "/:username"]);
const isOnboardingRoute = createRouteMatcher(["/onboarding"]);
const isAppRoute = createRouteMatcher(["/dashboard(.*)", "/onboarding(.*)"]);
export default clerkMiddleware(async (auth, req) => {
const { userId } = await auth();
if (!userId && isAppRoute(req)) {
return NextResponse.redirect(new URL("/sign-in", req.url));
}
if (userId && (req.nextUrl.pathname === "/sign-in" || req.nextUrl.pathname === "/sign-up")) {
return NextResponse.redirect(new URL("/redirect", req.url));
}
return NextResponse.next();
});
export const config = {
matcher: ["/((?!_next|.*\\..*).*)"],
};