start on auth middleware

This commit is contained in:
adueck 2024-11-26 16:59:16 +05:00
parent 9be5321d48
commit 1c11bf9cf2
1 changed files with 15 additions and 13 deletions

View File

@ -1,6 +1,20 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { cors } from "hono/cors";
const app = new Hono(); const app = new Hono();
app.use(cors());
app.use(async (c, next) => {
const cookie = c.req.header("Cookie") || "";
const r = await fetch("https://account.lingdocs.com/api/user", {
headers: { cookie },
});
const res = await r.json();
if (res.ok) {
c.set("user", res.user);
}
await next();
});
app.get("/", (c) => { app.get("/", (c) => {
// c.env.LINGDOCS_COUCHDB // c.env.LINGDOCS_COUCHDB
@ -8,19 +22,7 @@ app.get("/", (c) => {
}); });
app.get("/wa", async (c) => { app.get("/wa", async (c) => {
const cookie = c.req.header("Cookie") || ""; return c.json({ user: c.var.user });
const r = await fetch("https://account.lingdocs.com/api/user", {
headers: { cookie },
});
const { ok, user } = await r.json();
// const {
// headers: { cookie },
// } = c. req;
// if (!cookie) {
// return { req: null, res };
// }
// c.env.LINGDOCS_COUCHDB
return c.json({ ok, user });
}); });
export default app; export default app;