forked from NotFound-Team/CoreChain-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
27 lines (22 loc) · 734 Bytes
/
middleware.ts
File metadata and controls
27 lines (22 loc) · 734 Bytes
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
import { PUBLIC_ROUTES } from "@/configs/route";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(req: NextRequest) {
// const token = req.cookies.get("token")?.value;
const token = localStorage.getItem("token");
const pathname = req.nextUrl.pathname;
if (PUBLIC_ROUTES.includes(pathname)) {
return NextResponse.next();
}
if (pathname === "/") {
return NextResponse.next();
}
if (!token) {
return NextResponse.redirect(new URL("/login", req.url));
}
return NextResponse.next();
}
// Áp dụng middleware cho các route cần bảo vệ
export const config = {
matcher: ["/dashboard/:path*", "/chat/:path*", "/settings"],
};