diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 278296b..75a6800 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -11,6 +11,9 @@ model User { id String @id @default(auto()) @map("_id") @db.ObjectId email String @unique password String? + name String + surname String + admin Boolean @default(false) messageSent Chat[] messageReceived Chat[] @relation("chatReceived") diff --git a/src/pages/api/user/createUser.ts b/src/pages/api/user/createUser.ts index 633c933..71d2e09 100644 --- a/src/pages/api/user/createUser.ts +++ b/src/pages/api/user/createUser.ts @@ -4,11 +4,14 @@ import { PrismaClient } from '@prisma/client' export const prisma = new PrismaClient(); export default async function createUser(req: NextApiRequest, res: NextApiResponse) { - const {email, password} = req.query - if (!email || !password) return res.status(400).send({message: "error"}) + + const {email, password, name, surname} = req.body + + if (!email || !password) return res.status(400).send({message: req.body}) + const newUser = await prisma.user.create({ - data: {email, password}, + data: {email, password, name, surname}, }); return res.status(201).send({message: "createUser", newUser}); diff --git a/src/pages/register.jsx b/src/pages/register.jsx index 4adc9a6..7c364fa 100644 --- a/src/pages/register.jsx +++ b/src/pages/register.jsx @@ -27,30 +27,30 @@ export default function Register() { }; const onRegister = async (values) => { - alert(JSON.stringify(values, null, 2)); - // if (values.pwd !== values.pwd_bis) { - // alert("Les mots de passe ne correspondent pas"); - // return; - // } - // try { - // const response = await fetch("/api/user/", { - // method: "POST", - // headers: { - // "Content-Type": "application/json", - // }, - // body: JSON.stringify(values), - // }); - // const data = await response.json(); - // if (data.error) { - // alert(data.message); - // } else { - // console.log(data); - // alert("Inscription réussie"); - // router.push("/"); - // } - // } catch (error) { - // console.log(error); - // } + // alert(JSON.stringify(values, null, 2)); + if (values.password !== values.password_bis) { + alert("Les mots de passe ne correspondent pas"); + return; + } + try { + const response = await fetch("/api/user/", { + method: "PUT", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(values), + }); + const data = await response.json(); + if (data.error) { + alert(data.message); + } else { + console.log(data); + alert("Inscription réussie"); + router.push("/"); + } + } catch (error) { + console.log(error); + } }; const RightSide = () => ( @@ -68,10 +68,10 @@ export default function Register() { Prénom @@ -79,10 +79,10 @@ export default function Register() { Nom @@ -102,10 +102,10 @@ export default function Register() { Mot de passe @@ -114,10 +114,10 @@ export default function Register() { Confirmation du mot de passe diff --git a/yarn.lock b/yarn.lock index 219727f..829b8a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1035,9 +1035,14 @@ dependencies: "glob" "7.1.7" -"@next/swc-win32-x64-msvc@13.2.3": - "integrity" "sha512-aLG2MaFs4y7IwaMTosz2r4mVbqRyCnMoFqOcmfTi7/mAS+G4IMH0vJp4oLdbshqiVoiVuKrAfqtXj55/m7Qu1Q==" - "resolved" "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.2.3.tgz" +"@next/swc-linux-x64-gnu@13.2.3": + "integrity" "sha512-w5MyxPknVvC9LVnMenAYMXMx4KxPwXuJRMQFvY71uXg68n7cvcas85U5zkdrbmuZ+JvsO5SIG8k36/6X3nUhmQ==" + "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.2.3.tgz" + "version" "13.2.3" + +"@next/swc-linux-x64-musl@13.2.3": + "integrity" "sha512-CTeelh8OzSOVqpzMFMFnVRJIFAFQoTsI9RmVJWW/92S4xfECGcOzgsX37CZ8K982WHRzKU7exeh7vYdG/Eh4CA==" + "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.2.3.tgz" "version" "13.2.3" "@nodelib/fs.scandir@2.1.5":