Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

refactor: log unauthorized token reasons (#21)

authored by yoginth.com and committed by

GitHub f6079fda 58d31d7e

+7 -2
+7 -2
apps/api/src/middlewares/authMiddleware.ts
··· 1 1 import { LENS_API_URL } from "@hey/data/constants"; 2 + import logger from "@hey/helpers/logger"; 2 3 import type { Context, Next } from "hono"; 3 4 import { createRemoteJWKSet, jwtVerify } from "jose"; 4 5 ··· 8 9 cacheMaxAge: 60 * 60 * 12 9 10 }); 10 11 12 + const unauthorized = (c: Context) => c.body("Unauthorized", 401); 13 + 11 14 const authMiddleware = async (c: Context, next: Next) => { 12 15 const token = c.get("token"); 13 16 14 17 if (!token) { 15 - return c.body("Unauthorized", 401); 18 + logger.warn("missing token"); 19 + return unauthorized(c); 16 20 } 17 21 18 22 try { 19 23 await jwtVerify(token, JWKS); 20 24 } catch { 21 - return c.body("Unauthorized", 401); 25 + logger.warn("invalid token"); 26 + return unauthorized(c); 22 27 } 23 28 24 29 return next();