start on auth middleware
This commit is contained in:
parent
9be5321d48
commit
1c11bf9cf2
|
@ -1,6 +1,20 @@
|
|||
import { Hono } from "hono";
|
||||
import { cors } from "hono/cors";
|
||||
|
||||
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) => {
|
||||
// c.env.LINGDOCS_COUCHDB
|
||||
|
@ -8,19 +22,7 @@ app.get("/", (c) => {
|
|||
});
|
||||
|
||||
app.get("/wa", async (c) => {
|
||||
const cookie = c.req.header("Cookie") || "";
|
||||
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 });
|
||||
return c.json({ user: c.var.user });
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
|
Loading…
Reference in New Issue