todolist 추가

This commit is contained in:
koreacomp5
2025-10-09 15:06:45 +09:00
parent 66538d0d64
commit 02ed610045
2 changed files with 27 additions and 2 deletions

21
src/middleware.ts Normal file
View 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*"],
};