Files
comroots-backend/src/middlewares/isAuth.ts
T
2026-06-24 14:10:53 +02:00

12 lines
365 B
TypeScript

import { Context } from '@types'
import { MiddlewareFn } from 'type-graphql'
import { User } from '@entities'
export const isAuth: MiddlewareFn<Context> = async ({ context }, next) => {
if (!context.req.session.userId ||
!(await User.findOne({ where: { id: context.req.session.userId } }))
) {
throw new Error('Not authenticated.')
}
await next()
}