feat: add middlware to check auth route

This commit is contained in:
Sosokker 2025-03-12 15:18:48 +07:00
parent 9cc07b32df
commit 5a246a9627

22
frontend/middleware.ts Normal file
View File

@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const token = request.cookies.get("token");
if (!token) {
const url = request.nextUrl.clone();
url.pathname = "/auth/signin";
return NextResponse.redirect(url);
}
return NextResponse.next();
}
export const config = {
matcher: [
// This will match all paths that:
// - have at least one character after "/"
// - do NOT start with /_next/static, /_next/image, /favicon.ico, /hub, or /auth.
// (thus "/auth/signin", "/" and any "/hub" route are not processed by this middleware)
"/((?!_next/static|_next/image|favicon.ico|hub|auth).+)",
],
};