fix admin avatar upload using linked user instead of anonymous cookie
This commit is contained in:
@@ -27,9 +27,16 @@ export default async function avatarRoutes(app: FastifyInstance) {
|
|||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
"/me/avatar",
|
"/me/avatar",
|
||||||
{ preHandler: [app.requireUser], config: { rateLimit: { max: 10, timeWindow: "1 hour" } } },
|
{ preHandler: [app.requireUser, app.optionalAdmin], config: { rateLimit: { max: 10, timeWindow: "1 hour" } } },
|
||||||
async (req, reply) => {
|
async (req, reply) => {
|
||||||
const user = await prisma.user.findUnique({ where: { id: req.user!.id } });
|
// if admin, use their linked user instead of the anonymous cookie user
|
||||||
|
let userId = req.user!.id;
|
||||||
|
if (req.adminId) {
|
||||||
|
const admin = await prisma.adminUser.findUnique({ where: { id: req.adminId }, select: { linkedUserId: true } });
|
||||||
|
if (admin?.linkedUserId) userId = admin.linkedUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
if (!user) {
|
if (!user) {
|
||||||
reply.status(403).send({ error: "Not authenticated" });
|
reply.status(403).send({ error: "Not authenticated" });
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user