-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
61 lines (54 loc) · 1.48 KB
/
proxy.ts
File metadata and controls
61 lines (54 loc) · 1.48 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
58
59
60
61
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function proxy() {
// Add custom proxy logic here if needed
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token, req }) => {
const { pathname } = req.nextUrl;
// Public routes that don't require authentication
const publicRoutes = [
"/",
"/login",
"/api/auth",
"/api/health",
"/api/stats",
"/api/podcasts",
];
// Check if route is public
const isPublicRoute = publicRoutes.some(
(route) => pathname === route || pathname.startsWith(`${route}/`)
);
// Allow public routes
if (isPublicRoute) {
return true;
}
// API routes should handle their own auth and return 401
// Don't redirect API routes - let them handle auth themselves
if (pathname.startsWith("/api/")) {
return true;
}
// Require authentication for protected page routes only
return !!token;
},
},
pages: {
signIn: "/login",
},
}
);
export const config = {
matcher: [
/*
* Match all request paths except for:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - public folder
*/
"/((?!_next/static|_next/image|favicon.ico|.*\\..*|public).*)",
],
};