add auth token cleanup logic
This commit is contained in:
@@ -119,6 +119,13 @@ async function verifyAuthToken(cookies: Bun.CookieMap): Promise<User | null> {
|
||||
return user
|
||||
}
|
||||
|
||||
function startBackgroundAuthTokenCleanup() {
|
||||
const query = db.query("DELETE FROM auth_tokens WHERE expires_at_unix_ms < $time")
|
||||
setInterval(() => {
|
||||
query.run({ time: new Date().valueOf() })
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
async function signUp(request: Bun.BunRequest<"/api/sign-up">) {
|
||||
const body = await request.json().catch(() => {
|
||||
throw new HttpError(500)
|
||||
@@ -199,4 +206,4 @@ async function logout(request: Bun.BunRequest<"/api/logout">, user: User): Promi
|
||||
return new Response(undefined, { status: 204 })
|
||||
}
|
||||
|
||||
export { authenticated, signUp, login, logout }
|
||||
export { authenticated, signUp, login, logout, startBackgroundAuthTokenCleanup }
|
||||
|
Reference in New Issue
Block a user