2024-12-01 23:34:04 +00:00
|
|
|
import { Unauthorized } from '$lib/server/api/common/utils/exceptions';
|
2024-11-23 22:49:16 +00:00
|
|
|
import type { Sessions, Users } from '$lib/server/api/databases/postgres/tables';
|
|
|
|
|
import type { MiddlewareHandler } from 'hono';
|
|
|
|
|
import { createMiddleware } from 'hono/factory';
|
2024-09-04 23:04:41 +00:00
|
|
|
|
2024-11-23 22:49:16 +00:00
|
|
|
export const requireFullAuth: MiddlewareHandler<{
|
|
|
|
|
Variables: {
|
|
|
|
|
session: Sessions;
|
|
|
|
|
user: Users;
|
|
|
|
|
};
|
|
|
|
|
}> = createMiddleware(async (c, next) => {
|
|
|
|
|
const session = c.var.session;
|
|
|
|
|
if (!session || (session?.twoFactorAuthEnabled && !session?.twoFactorVerified)) {
|
|
|
|
|
throw Unauthorized('You must be logged in to access this resource');
|
|
|
|
|
}
|
|
|
|
|
return next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const requireTempAuth: MiddlewareHandler<{
|
2024-12-01 23:34:04 +00:00
|
|
|
Variables: {
|
|
|
|
|
session: Sessions;
|
|
|
|
|
user: Users;
|
|
|
|
|
};
|
2024-09-04 23:04:41 +00:00
|
|
|
}> = createMiddleware(async (c, next) => {
|
2024-12-01 23:34:04 +00:00
|
|
|
const session = c.var.session;
|
|
|
|
|
if (!session) {
|
|
|
|
|
throw Unauthorized('You must be logged in to access this resource');
|
|
|
|
|
}
|
|
|
|
|
return next();
|
|
|
|
|
});
|