Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { PERMISSIONS } from "@hey/data/constants";
2import type { Context, Next } from "hono";
3import lensPg from "@/utils/lensPg";
4
5const proMiddleware = async (c: Context, next: Next) => {
6 const account = c.get("account");
7
8 if (!account) {
9 return c.body("Unauthorized", 401);
10 }
11
12 try {
13 const groupMemberShip = (await lensPg.query(
14 `
15 SELECT account
16 FROM "group"."member"
17 WHERE "group" = $1 AND account = $2
18 LIMIT 1;
19 `,
20 [
21 `\\x${PERMISSIONS.SUBSCRIPTION.replace("0x", "").toLowerCase()}`,
22 `\\x${account.replace("0x", "").toLowerCase()}`
23 ]
24 )) as Array<{ account: Buffer }>;
25
26 const canRequest =
27 account === `0x${groupMemberShip[0].account.toString("hex")}`;
28
29 if (!canRequest) {
30 return c.body("Unauthorized", 401);
31 }
32
33 return next();
34 } catch {
35 return c.body("Unauthorized", 401);
36 }
37};
38
39export default proMiddleware;