first
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import type { Handler } from 'hono';
|
||||
import { officerdb, TokenBlacklist, lt } from 'officerdb';
|
||||
|
||||
// Cleanup expired blacklist entries (can be called periodically)
|
||||
export async function cleanupExpiredTokens() {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
await officerdb.delete(TokenBlacklist).where(lt(TokenBlacklist.expiresAt, now));
|
||||
}
|
||||
|
||||
export const signoutHandler: Handler = async (ctx) => {
|
||||
const user = ctx.get('user') as { jti: string; exp: number };
|
||||
|
||||
// Add token to blacklist
|
||||
await officerdb
|
||||
.insert(TokenBlacklist)
|
||||
.values({
|
||||
jti: user.jti,
|
||||
expiresAt: user.exp,
|
||||
})
|
||||
.onConflictDoNothing();
|
||||
|
||||
// Opportunistic cleanup of expired tokens (non-blocking)
|
||||
cleanupExpiredTokens().catch(() => {});
|
||||
|
||||
return ctx.json({ ok: true });
|
||||
};
|
||||
Reference in New Issue
Block a user