-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
45 lines (37 loc) · 1.56 KB
/
middleware.ts
File metadata and controls
45 lines (37 loc) · 1.56 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
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
// For Firebase auth, we'll rely on client-side auth checks
// This middleware is simplified and mainly for route protection
// Public routes that don't require authentication
const publicRoutes = ["/", "/features", "/docs", "/api", "/auth"]
// Check if the current path is a public route
const isPublicRoute = publicRoutes.some(
(route) => request.nextUrl.pathname === route || request.nextUrl.pathname.startsWith(`${route}/`),
)
// For Firebase, we'll handle most auth in the client components
// This is just a basic route protection
if (!isPublicRoute) {
// We'll redirect unauthenticated users to the sign-in page
// The actual auth check will happen in the client components
const signInUrl = new URL("/auth/signin", request.url)
signInUrl.searchParams.set("callbackUrl", request.nextUrl.pathname)
// Note: This is a simplified approach. For Firebase, most auth checks
// will happen client-side in the components themselves
return NextResponse.next()
}
return NextResponse.next()
}
// See "Matching Paths" below to learn more
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
"/((?!_next/static|_next/image|favicon.ico).*)",
],
}