diff --git a/src/app/api/cron/health-check/route.ts b/src/app/api/cron/health-check/route.ts index 12663eb..e5d3086 100644 --- a/src/app/api/cron/health-check/route.ts +++ b/src/app/api/cron/health-check/route.ts @@ -1,5 +1,5 @@ import { db } from "@/server/db" -import { headers } from "next/headers" +import type { NextRequest } from "next/server" import { NextResponse } from "next/server" import { env } from "@/env" @@ -7,14 +7,15 @@ import { env } from "@/env" export const dynamic = "force-dynamic" export const maxDuration = 59 -export async function GET() { +export async function GET(request: NextRequest) { try { // Verify cron secret in production only - if (env.NODE_ENV === "production") { - const headersList = await headers() - const cronSecret = headersList.get("x-vercel-cron") - if (cronSecret !== env.CRON_SECRET) { - return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + if (env.VERCEL_ENV === "production") { + const authHeader = request.headers.get("authorization") + if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) { + return new Response("Unauthorized", { + status: 401, + }) } } diff --git a/src/components/organisms/header/header.tsx b/src/components/organisms/header/header.tsx index 55e20f8..d18a999 100644 --- a/src/components/organisms/header/header.tsx +++ b/src/components/organisms/header/header.tsx @@ -150,7 +150,10 @@ export function Header() { - + Merch diff --git a/src/env.js b/src/env.js index 608863b..7fb63dd 100644 --- a/src/env.js +++ b/src/env.js @@ -16,6 +16,7 @@ export const env = createEnv({ */ server: { NODE_ENV: z.enum(["development", "test", "production"]), + VERCEL_ENV: z.enum(["development", "test", "production"]).optional(), STRIPE_SECRET_KEY: z .string() .min(1) @@ -48,6 +49,7 @@ export const env = createEnv({ */ runtimeEnv: { NODE_ENV: process.env.NODE_ENV, + VERCEL_ENV: process.env.VERCEL_ENV, STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY, STRIPE_MEMBERSHIP_PRICE_ID: process.env.STRIPE_MEMBERSHIP_PRICE_ID, NEXT_PUBLIC_SANITY_PROJECT_ID: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,