You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
932 B
33 lines
932 B
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
import prisma from '../../../lib/prisma'
|
|
import { getSession } from 'next-auth/react'
|
|
|
|
|
|
// UPDATE /api/profile
|
|
// Required fields in body: title
|
|
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
|
const { bioValue } = req.body;
|
|
const session = await getSession({ req });
|
|
|
|
if (req.method === "PUT") {
|
|
if (session) {
|
|
const updateUserProfil = await prisma.user.update({
|
|
where: { email: session.user.email },
|
|
data: {
|
|
profile: {
|
|
update: {
|
|
bio: bioValue,
|
|
},
|
|
},
|
|
}
|
|
})
|
|
res.status(200).send({ result: updateUserProfil, message: 'Profiled updated !' });
|
|
} else {
|
|
res.status(401).send({ message: 'Unauthorized' })
|
|
}
|
|
} else {
|
|
throw new Error(
|
|
`The HTTP ${req.method} method is not supported at this route.`
|
|
);
|
|
}
|
|
} |