4bba529ba8
Support TOTP 2fa, allow for changing password, add session management and account removal.
16 lines
405 B
TypeScript
16 lines
405 B
TypeScript
import type { H3Event } from 'h3';
|
|
import { auth } from '~~/lib/auth';
|
|
|
|
export const protectRoute = async (event: H3Event) => {
|
|
const sessionData = await auth.api.getSession({ headers: event.headers });
|
|
|
|
if (sessionData === null) {
|
|
throw createError({
|
|
statusCode: 401,
|
|
statusMessage: 'Unauthorized',
|
|
});
|
|
}
|
|
|
|
event.context.user = sessionData.user;
|
|
};
|