-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
34 lines (26 loc) · 1.06 KB
/
Copy pathproxy.ts
File metadata and controls
34 lines (26 loc) · 1.06 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
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
// Paths that need authentication
const protectedPaths = ["/dashboard", "/groups", "/tasks", "/schedule", "/plan"];
// Publicly accessible pages
const publicPaths = ["/login", "/signup", "/"];
export default function proxy(req: NextRequest) {
const { pathname } = req.nextUrl;
// Check if cookie is set (you set this manually after Firebase login)
const isAuthenticated = req.cookies.has("authToken");
// ✅ Skip auth checks entirely for signup and login
if (publicPaths.some((path) => pathname.startsWith(path))) {
return NextResponse.next();
}
// 🚫 Redirect unauthenticated users away from protected pages
if (protectedPaths.some((path) => pathname.startsWith(path)) && !isAuthenticated) {
const url = req.nextUrl.clone();
url.pathname = "/login";
return NextResponse.redirect(url);
}
// ✅ Allow everything else
return NextResponse.next();
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|assets|api).*)"],
};