Remove client address and adding cron to remove stale sessions every day at 2AM.

This commit is contained in:
Bradley Shellnut 2024-01-23 14:07:43 -08:00
parent 9f4aafe658
commit 019798eb0b
3 changed files with 20 additions and 1 deletions

View file

@ -17,7 +17,7 @@ export const authentication: Handle = async function ({ event, resolve }) {
const ip = event.request.headers.get('x-forwarded-for') as string;
const country = event.request.headers.get('x-vercel-ip-country') as string;
event.locals.ip = dev ? '127.0.0.1' : ip || event.getClientAddress();
event.locals.ip = dev ? '127.0.0.1' : ip; // || event.getClientAddress();
event.locals.country = dev ? 'us' : country;
const sessionId = event.cookies.get(lucia.sessionCookieName);

View file

@ -0,0 +1,11 @@
import type { RequestHandler } from "@sveltejs/kit";
import { lucia } from "$lib/server/auth";
export const GET: RequestHandler = async ({ request }) => {
if (request?.headers?.get('Authorization') === `Bearer ${process.env.CRON_SECRET}`) {
await lucia.deleteExpiredSessions();
return new Response('Success', { status: 200 });
} else {
return new Response('Unauthorized', { status: 401 });
}
}

8
vercel.json Normal file
View file

@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/crons/cleanupSessions",
"schedule": "0 2 * * *"
}
]
}