import type { MiddlewareHandler } from 'hono'; import { resolveAuthToken } from '@@/auth-token'; import * as errors from '@@/custom-errors'; import { isLockdown, noteBlocked } from '../api/auth/panic'; import { getUserById, isTokenBlacklisted } from 'officerdb'; export const userMiddleware: MiddlewareHandler = async function (ctx, next) { // Duress lockdown: reject every authenticated request, cutting off all existing sessions. if (isLockdown()) { noteBlocked(`${ctx.req.method} ${ctx.req.path}`); throw errors.UNAUTHORIZED(); } const { authorization } = ctx.req.header(); // Support token in query param for media elements (