From 062f50b3a277bc529e226d32982c0eddc1fe08a9 Mon Sep 17 00:00:00 2001 From: adueck Date: Thu, 28 Nov 2024 02:23:43 +0500 Subject: [PATCH] now custom domain for functions is set up and auth working! just need to get the CI/CD set up and the architecture diagram updated and firebase cleaned away --- functions/lambda/index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/functions/lambda/index.ts b/functions/lambda/index.ts index 8bc1607..1927058 100644 --- a/functions/lambda/index.ts +++ b/functions/lambda/index.ts @@ -21,6 +21,26 @@ import { getEnv } from "../lib/env-helper"; const app = new Hono(); app.get("/publish", async (c) => { + // check if caller is authorized as lingdocs admin + // might be nicer to abstract this into some middleware + const cookie = c.req.header("cookie"); + if (!cookie) { + c.status(401); + return c.json({ + ok: false, + error: "unauthorized", + }); + } + const r = await fetch("https://account.lingdocs.com/api/user", { + headers: { Cookie: cookie }, + }); + const { ok, user } = await r.json(); + if (ok !== true || typeof user !== "object" || !user.admin) { + return c.json({ + ok: false, + error: "unauthorized", + }); + } const vars = getEnv(c); const auth = new google.auth.GoogleAuth({ credentials: {