mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
createUser + update de la BD
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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});
|
||||
|
||||
+32
-32
@@ -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() {
|
||||
<FormControl>
|
||||
<FormLabel>Prénom</FormLabel>
|
||||
<Input
|
||||
id="prenom"
|
||||
id="surname"
|
||||
type="text"
|
||||
placeholder="Prénom"
|
||||
{...register("prenom", {
|
||||
{...register("surname", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
@@ -79,10 +79,10 @@ export default function Register() {
|
||||
<FormControl>
|
||||
<FormLabel>Nom</FormLabel>
|
||||
<Input
|
||||
id="nom"
|
||||
id="name"
|
||||
type="text"
|
||||
placeholder="Nom"
|
||||
{...register("nom", {
|
||||
{...register("name", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
@@ -102,10 +102,10 @@ export default function Register() {
|
||||
<FormControl mb={"1rem"}>
|
||||
<FormLabel>Mot de passe</FormLabel>
|
||||
<Input
|
||||
id="pwd"
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register("pwd", {
|
||||
{...register("password", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
@@ -114,10 +114,10 @@ export default function Register() {
|
||||
<FormControl mb={"1rem"}>
|
||||
<FormLabel>Confirmation du mot de passe</FormLabel>
|
||||
<Input
|
||||
id="pwd_bis"
|
||||
id="password_bis"
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register("pwd_bis", {
|
||||
{...register("password_bis", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user