Skip to content

Commit

Permalink
improve cron debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Jan 3, 2025
1 parent d9c8b2e commit f74c0f8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/api/cron/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ export async function POST(req: Request) {
throw new Error("CRON_API_KEY is not defined");
}

if (
req.headers.get("Authorization") !== `Bearer ${process.env.CRON_API_KEY}`
) {
const auth = req.headers.get("Authorization");
if (auth !== `Bearer ${process.env.CRON_API_KEY}`) {
logError("api/cron: Unauthorized", {
req: {
len: req.headers.get("Authorization")?.length,
pref: req.headers.get("Authorization")?.substring(0, 3),
len: auth?.length,
pref: auth?.substring(0, 10),
suf: auth?.substring(auth.length - 3),
},
env: {
len: process.env.CRON_API_KEY?.length,
pref: process.env.CRON_API_KEY?.substring(0, 3),
suf: process.env.CRON_API_KEY?.substring(
process.env.CRON_API_KEY.length - 3,
),
},
});
return Response.json({ message: "Unauthorized" }, { status: 401 });
Expand Down

0 comments on commit f74c0f8

Please sign in to comment.