Skip to content

Commit

Permalink
Merge pull request #2 from Dadangdut33/rewrite
Browse files Browse the repository at this point in the history
fix cron
  • Loading branch information
Dadangdut33 committed Jun 6, 2024
2 parents c83f7bf + a37f5bd commit 80e3633
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
LOGFLARE_API_KEY=
LOGFLARE_SOURCE_TOKEN=
CLEAN_SESSIONS_SECRET=
CRON_SECRET=
UMAMI_ID=
5 changes: 1 addition & 4 deletions src/app/api/public/(key-protected)/clear-session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ export async function GET(req: NextRequest) {

const reqData = await req.json();
// if the request does not contain the API_KEY, return an error
if (!reqData.API_KEY) {
return NextResponse.json({ success: 0, message: "Invalid request" }, { status: 400 });
}

if (reqData.API_KEY !== env.CLEAN_SESSIONS_SECRET) {
if (req.headers.get("Authorization") !== `Bearer ${env.CRON_SECRET}`) {
return NextResponse.json({ success: 0, message: "Invalid API_KEY" }, { status: 403 });
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const env = createEnv({
DB_CA: z.string().min(1),
LOGFLARE_API_KEY: z.string().min(1),
LOGFLARE_SOURCE_TOKEN: z.string().min(1),
CLEAN_SESSIONS_SECRET: z.string().min(1),
CRON_SECRET: z.string().min(1),
},
client: {
// NEXT_PUBLIC_PUBLISHABLE_KEY: z.string().min(1),
Expand Down
2 changes: 1 addition & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"crons": [{
"path": "/api/public/clear-session?key=${CLEAN_SESSIONS_SECRET}",
"path": "/api/public/clear-session",
"schedule": "0 0 * * *"
}]
}

0 comments on commit 80e3633

Please sign in to comment.