-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
37 lines (31 loc) · 937 Bytes
/
proxy.ts
File metadata and controls
37 lines (31 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
function getRoutePath(envValue: string | undefined, fallback: string) {
if (!envValue) {
return fallback;
}
try {
return new URL(envValue).pathname;
} catch {
return envValue;
}
}
const signInPath = getRoutePath(process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL, "/sign-in");
const signUpPath = getRoutePath(process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL, "/sign-up");
const isPublicRoute = createRouteMatcher([signInPath, `${signInPath}(.*)`, signUpPath, `${signUpPath}(.*)`]);
export default clerkMiddleware(
async (auth, req) => {
if (!isPublicRoute(req)) {
await auth.protect();
}
},
{
signInUrl: signInPath,
signUpUrl: signUpPath,
},
);
export const config = {
matcher: [
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpg|jpeg|png|gif|svg|ttf|woff2?|ico|json|csv|pdf|zip)).*)",
"/(api|trpc)(.*)",
],
};