import { PrismaClient } from '../../generated/prisma' import { withAccelerate } from "@prisma/extension-accelerate" import type { FastifyRequest, FastifyReply } from 'fastify'; import type { OnBehalfQuery } from '../types'; import logger from './logger'; const prisma = new PrismaClient().$extends(withAccelerate()) export async function getTargetUser( request: FastifyRequest, reply: FastifyReply ) { const userId = request.session.get('user_id'); const requester = await prisma.user.findFirstOrThrow({ where: { id: userId } }); if (!requester.patreonId) { reply.status(500).send({ error: true, message: 'Requesting user does not have a patreonId defined. Please log out and in, then contact admin if error persists.' }); throw new Error('Unauthorized'); // Prevent downstream execution } return requester; }