-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
57 lines (50 loc) · 1.21 KB
/
Copy pathproxy.ts
File metadata and controls
57 lines (50 loc) · 1.21 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// proxy.ts
import { auth } from "@/server/auth";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const PUBLIC_PATHS = [
"/login",
"/book",
"/support",
"/pricing",
"/services",
"/about",
"/contact",
"/privacy",
"/terms",
"/blog",
"/nonprofits",
"/careers",
"/apple-business",
"/ai-risk",
"/ownership",
"/portal",
"/api/auth",
"/api/trpc",
"/api/webhooks",
"/api/health",
"/api/tickets/reply",
"/api/leads/checklist",
"/api/leads/prompt-framework",
"/api/leads/tech-debt",
"/api/tools/dmarc-check",
"/resources",
"/tools",
];
export default auth((req: NextRequest & { auth: unknown }) => {
const { pathname } = req.nextUrl;
const isPublic =
PUBLIC_PATHS.some((p) => pathname.startsWith(p)) ||
pathname.startsWith("/(site)") ||
pathname === "/";
if (isPublic) return NextResponse.next();
if (!(req as { auth: unknown }).auth) {
const loginUrl = new URL("/login", req.url);
loginUrl.searchParams.set("callbackUrl", pathname);
return NextResponse.redirect(loginUrl);
}
return NextResponse.next();
});
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\\..*).*)"],
};