![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/src/pages/api/admin/ |
import type { NextApiRequest, NextApiResponse } from 'next';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).json({ message: 'Unauthorized' });
}
if (req.method === 'POST') {
try {
// Update the user's role to ADMIN
const updatedUser = await prisma.user.update({
where: {
email: session.user.email as string
},
data: {
role: 'ADMIN'
}
});
return res.status(200).json(updatedUser);
} catch (error) {
console.error('Error updating user role:', error);
return res.status(500).json({ message: 'Error updating user role' });
}
}
return res.status(405).json({ message: 'Method not allowed' });
}