export type Ctx = { Variables: { session: Session | null } };
export const app = new Hono<Ctx>()
.use(async (c, n) => {
const token = getCookie(c, "session") ?? "";
const session = await validateSession(token);
c.set("session", session);
await n();
})
.post(
"/sign-out",
async (c, n) => {
if (!c.var.session) {
throw new HTTPException(401, { message: "unauthorized" });
}
await n();
},
async (c) => {
c.var.session; // currently Session | null but it should be Session
},
);
export type Ctx = { Variables: { session: Session | null } };
export const app = new Hono<Ctx>()
.use(async (c, n) => {
const token = getCookie(c, "session") ?? "";
const session = await validateSession(token);
c.set("session", session);
await n();
})
.post(
"/sign-out",
async (c, n) => {
if (!c.var.session) {
throw new HTTPException(401, { message: "unauthorized" });
}
await n();
},
async (c) => {
c.var.session; // currently Session | null but it should be Session
},
);