Files
droidclaw/server/src/middleware/auth.ts
Sanju Sivalingam 577c195862 feat: add REST routes for devices, goals, and health
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 14:21:11 +05:30

25 lines
649 B
TypeScript

import type { Context, Next } from "hono";
import { auth } from "../auth.js";
/** Hono Env type for routes protected by sessionMiddleware */
export type AuthEnv = {
Variables: {
user: { id: string; name: string; email: string; [key: string]: unknown };
session: { id: string; userId: string; [key: string]: unknown };
};
};
export async function sessionMiddleware(c: Context, next: Next) {
const session = await auth.api.getSession({
headers: c.req.raw.headers,
});
if (!session) {
return c.json({ error: "unauthorized" }, 401);
}
c.set("user", session.user);
c.set("session", session.session);
await next();
}