Phase 3. 인증 및 공통 레이아웃 작업

This commit is contained in:
2026-06-09 23:37:33 +09:00
parent a93a6fa8e1
commit dbf9b3e180
17 changed files with 1092 additions and 71 deletions
+30
View File
@@ -0,0 +1,30 @@
import { getToken } from "next-auth/jwt";
import { NextResponse, type NextRequest } from "next/server";
const PUBLIC_PATHS = ["/login"];
export async function proxy(request: NextRequest) {
const { pathname, search } = request.nextUrl;
const isPublicPath = PUBLIC_PATHS.includes(pathname);
const token = await getToken({
req: request,
secret: process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET,
});
if (!token && !isPublicPath) {
const loginUrl = new URL("/login", request.url);
loginUrl.searchParams.set("callbackUrl", `${pathname}${search}`);
return NextResponse.redirect(loginUrl);
}
if (token && isPublicPath) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\..*).*)"],
};