mirror of
https://github.com/BradNut/TofuStack
synced 2025-09-08 17:40:26 +00:00
15 lines
No EOL
470 B
TypeScript
15 lines
No EOL
470 B
TypeScript
import type { MiddlewareHandler } from "hono";
|
|
import { createMiddleware } from "hono/factory";
|
|
import type { Session, User } from "lucia";
|
|
import { Unauthorized } from "../common/exceptions";
|
|
|
|
export const requireAuth: MiddlewareHandler<{
|
|
Variables: {
|
|
session: Session;
|
|
user: User;
|
|
};
|
|
}> = createMiddleware(async (c, next) => {
|
|
const user = c.var.user;
|
|
if (!user) throw Unauthorized('You must be logged in to access this resource');
|
|
return next();
|
|
}); |