mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
16 lines
532 B
TypeScript
16 lines
532 B
TypeScript
import {Unauthorized} from '$lib/server/api/common/exceptions';
|
|
import type {Sessions} from '$lib/server/api/databases/postgres/tables';
|
|
import type {MiddlewareHandler} from 'hono';
|
|
import {createMiddleware} from 'hono/factory';
|
|
import type {User} from 'lucia';
|
|
|
|
export const requireAuth: MiddlewareHandler<{
|
|
Variables: {
|
|
session: Sessions;
|
|
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();
|
|
});
|