Build Phase 2 judge vertical slice

This commit is contained in:
2026-08-06 22:42:39 -06:00
parent e6329ecabb
commit ec274419c3
41 changed files with 2945 additions and 669 deletions

View File

@@ -0,0 +1,24 @@
import type { MiddlewareHandler } from "hono"
import { failure } from "../http"
import { getSessionUser, type AuthUser } from "./session"
export interface AppEnv {
Variables: {
user: AuthUser | null
}
}
export const optionalAuth: MiddlewareHandler<AppEnv> = async (c, next) => {
c.set("user", await getSessionUser(c))
await next()
}
export const requireAuth: MiddlewareHandler<AppEnv> = async (c, next) => {
const user = await getSessionUser(c)
if (!user) {
return failure(c, 401, "login-required", "Authentication required")
}
c.set("user", user)
await next()
}