Allow passing CRON_SECRET via query parameter, use production only, don't return response directly

This commit is contained in:
2024-12-31 19:54:21 -06:00
parent 7c30bb7082
commit 23c6b68179

View File

@@ -200,12 +200,15 @@ export default async function handler(
} }
// Ensure the cron request is authenticated // Ensure the cron request is authenticated
if (process.env.NODE_ENV !== "development") { if (process.env.NODE_ENV === "production") {
const authHeader = req.headers["authorization"]; const authHeader = req.headers["authorization"];
if (authHeader !== `Bearer ${CRON_SECRET}`) { const secretQueryParam = req.query.secret;
return new Response("Unauthorized", { if (
status: 401, authHeader !== `Bearer ${CRON_SECRET}` &&
}); secretQueryParam !== CRON_SECRET
) {
res.status(401).json({ error: "Unauthorized" });
return;
} }
} }