Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cron #2

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 * * *"
}]
}