todolist 추가
This commit is contained in:
21
src/middleware.ts
Normal file
21
src/middleware.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse, NextRequest } from "next/server";
|
||||
|
||||
const protectedApi = [
|
||||
/^\/api\/posts\/[^/]+\/pin$/,
|
||||
/^\/api\/posts\/[^/]+\/approve$/,
|
||||
];
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
const { pathname } = req.nextUrl;
|
||||
const needAuth = protectedApi.some((re) => re.test(pathname));
|
||||
if (!needAuth) return NextResponse.next();
|
||||
const uid = req.cookies.get("uid")?.value;
|
||||
if (!uid) return new NextResponse(JSON.stringify({ error: "Unauthorized" }), { status: 401 });
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/api/:path*"],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user