Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import parseJwt from "@hey/helpers/parseJwt";
2import type { JwtPayload } from "@hey/types/jwt";
3import type { Context, Next } from "hono";
4
5const authContext = async (ctx: Context, next: Next) => {
6 const token = ctx.req.raw.headers.get("X-Access-Token");
7 const payload: JwtPayload = parseJwt(token as string);
8
9 if (!payload.act.sub) {
10 ctx.set("owner", null);
11 ctx.set("account", null);
12 ctx.set("token", null);
13 return next();
14 }
15
16 ctx.set("owner", payload.sub);
17 ctx.set("account", payload.act.sub);
18 ctx.set("token", token);
19 return next();
20};
21
22export default authContext;