This commit is contained in:
parent
1c11bf9cf2
commit
2efa3086f2
|
@ -1,21 +1,29 @@
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
|
import { createMiddleware } from "hono/factory";
|
||||||
|
import type { LingdocsUser } from "../../website/src/types/account-types";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
app.use(async (c, next) => {
|
const authMiddleware = createMiddleware<{
|
||||||
|
Variables: {
|
||||||
|
user: LingdocsUser;
|
||||||
|
};
|
||||||
|
}>(async (c, next) => {
|
||||||
const cookie = c.req.header("Cookie") || "";
|
const cookie = c.req.header("Cookie") || "";
|
||||||
const r = await fetch("https://account.lingdocs.com/api/user", {
|
const r = await fetch("https://account.lingdocs.com/api/user", {
|
||||||
headers: { cookie },
|
headers: { cookie },
|
||||||
});
|
});
|
||||||
const res = await r.json();
|
const res = (await r.json()) as { ok: boolean; user: LingdocsUser };
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
c.set("user", res.user);
|
c.set("user", res.user);
|
||||||
}
|
}
|
||||||
await next();
|
await next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(authMiddleware);
|
||||||
|
|
||||||
app.get("/", (c) => {
|
app.get("/", (c) => {
|
||||||
// c.env.LINGDOCS_COUCHDB
|
// c.env.LINGDOCS_COUCHDB
|
||||||
return c.text("Hi from hono updated");
|
return c.text("Hi from hono updated");
|
||||||
|
|
Loading…
Reference in New Issue