diff --git a/frontend/middleware.ts b/frontend/middleware.ts new file mode 100644 index 0000000..038f5fd --- /dev/null +++ b/frontend/middleware.ts @@ -0,0 +1,35 @@ +import { NextRequest, NextResponse } from "next/server"; + +const protectedRoutes = [ + "/dashboard", + "/projects", + "/workspace", + "/chat", + "/insights", +]; + +export function middleware(req: NextRequest) { + const token = + req.cookies.get("sb-access-token")?.value || + req.headers.get("authorization"); + + const isProtectedRoute = protectedRoutes.some((route) => + req.nextUrl.pathname.startsWith(route) + ); + + if (isProtectedRoute && !token) { + return NextResponse.redirect(new URL("/login", req.url)); + } + + return NextResponse.next(); +} + +export const config = { + matcher: [ + "/dashboard/:path*", + "/projects/:path*", + "/workspace/:path*", + "/chat/:path*", + "/insights/:path*", + ], +}; \ No newline at end of file