import type { Handler } from 'hono';
import { blacklistToken, cleanupExpiredTokens } from 'officerdb';

export const signoutHandler: Handler = async (ctx) => {
  const user = ctx.get('user') as { jti: string; exp: number };

  await blacklistToken(user.jti, user.exp);

  // Opportunistic cleanup of expired tokens (non-blocking)
  cleanupExpiredTokens().catch(() => {});

  return ctx.json({ ok: true });
};
