-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmiddleware.ts
More file actions
38 lines (31 loc) · 1.12 KB
/
middleware.ts
File metadata and controls
38 lines (31 loc) · 1.12 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
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
// Redirect /home to /
if (pathname === "/home" || pathname.startsWith("/home/")) {
const url = request.nextUrl.clone()
url.pathname = "/"
return NextResponse.redirect(url)
}
// Protected routes - redirect to home if not authenticated
// Note: We can't access Firebase auth state in middleware (edge runtime)
// So we rely on client-side protection via ProtectedRoute component
const protectedPaths = ["/notes", "/notes/"]
const isProtectedPath = protectedPaths.some((path) => pathname.startsWith(path))
if (isProtectedPath) {
// Check for auth cookie (set by Firebase auth)
const hasAuthCookie = request.cookies.has("__session")
// For now, allow access - client-side will handle redirect
// In production, implement proper auth check here
return NextResponse.next()
}
return NextResponse.next()
}
export const config = {
matcher: [
"/home/:path*",
"/notes/:path*",
"/auth/:path*",
],
}