WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 38 lines 1.3 kB view raw
1import type { Context, Next } from "hono"; 2import type { AppContext } from "../lib/app-context.js"; 3import type { Variables } from "../types.js"; 4import { handleRouteError } from "../lib/route-errors.js"; 5import { getActiveBans } from "../routes/helpers.js"; 6 7/** 8 * Middleware that checks if the authenticated user is banned. 9 * 10 * Must be used AFTER requireAuth (depends on c.get("user") being set). 11 * Fails closed: if the ban check fails, the request is denied. 12 * 13 * Usage: 14 * app.post("/api/topics", requireAuth(ctx), requireNotBanned(ctx), async (c) => { ... }); 15 */ 16export function requireNotBanned(ctx: AppContext) { 17 return async (c: Context<{ Variables: Variables }>, next: Next) => { 18 const user = c.get("user"); 19 if (!user) { 20 return c.json({ error: "Authentication required" }, 401); 21 } 22 23 try { 24 const bannedUsers = await getActiveBans(ctx.db, [user.did]); 25 if (bannedUsers.has(user.did)) { 26 return c.json({ error: "You are banned from this forum" }, 403); 27 } 28 } catch (error) { 29 return handleRouteError(c, error, "Unable to verify ban status", { 30 operation: `${c.req.method} ${c.req.path} - ban check`, 31 logger: ctx.logger, 32 userId: user.did, 33 }); 34 } 35 36 await next(); 37 }; 38}