gucci
This commit is contained in:
20
middleware.ts
Normal file
20
middleware.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { SESSION_COOKIE_NAME, verifySessionToken } from "./lib/auth";
|
||||
|
||||
export async function middleware(req: NextRequest) {
|
||||
const token = req.cookies.get(SESSION_COOKIE_NAME)?.value;
|
||||
const session = token ? await verifySessionToken(token) : null;
|
||||
|
||||
if (!session) {
|
||||
const loginUrl = new URL("/login", req.url);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/dashboard/:path*", "/api/files/:path*"],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user