⚡️ ⚡️ add - ajout d'une page mon compte connecter a la bdd + API + routes

This commit is contained in:
eric committed 2022-11-10 15:40:00 +01:00
1 parent ae437a097b
commit 38159b90c1
12 files changed
+303 -16

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
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.`
);
}
}