You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I´m having problems when I try to save information of two diferente schemas in the same petion.
Context: The proyect it is in next.js and I'm using mongodb as database provider. It throws the next error:Algo a ido mal User validation failed: password: The password is required, email: E-mail is required, lastname: Path lastname is required., firstname: Path firstname is required. PostData: The user.save() works correctly.
`export default async function register(request, response) {
await connectDB();
const { Firstname, Lastname, Email, Password } = request.body;
const stripe = Stripe(process.env.SK_PRIVATE);
console.log(Firstname, Lastname, Email, Password);
try {
//Registro de Usuario de la pagina en la base de datos
const UserFound = await User.findOne({ Email });
if (UserFound)
return response
.status(400)
.json({ message: "El email ya ha sido registrado" });
if (!Password || Password.length < 7)
return response
.status(400)
.json({ message: "At least needs 7 characters" });
const hash = await bcrypt.hash(Password, 10);
const newUser = new User({
firstname: Firstname,
lastname: Lastname,
email: Email,
password: hash,
});
const userSaved = await newUser.save();
console.log("hecho");
//Registro de Customer user data en la base de datos
const customer = await stripe.customers.create({
name: Firstname,
email: Email,
});
const newCustomer = new Customer({
userId: userSaved._id,
stripeCustomerId: customer.id,
});
const customerSaved = await newCustomer.save();
console.log("Cliente guardado con éxito:", customerSaved);
response.json({
message: "Se ha registrado correctamente",
});
console.log("Datos recibidos en el servidor:", hash, Email);
} catch (error) {
response.status(500).json({ message: error.message });
console.log("Algo a ido mal", error.message);
}
}
`
The text was updated successfully, but these errors were encountered:
I´m having problems when I try to save information of two diferente schemas in the same petion.
Context: The proyect it is in next.js and I'm using mongodb as database provider. It throws the next error:Algo a ido mal User validation failed: password: The password is required, email: E-mail is required, lastname: Path lastname is required., firstname: Path firstname is required. PostData: The user.save() works correctly.
`export default async function register(request, response) {
await connectDB();
const { Firstname, Lastname, Email, Password } = request.body;
const stripe = Stripe(process.env.SK_PRIVATE);
console.log(Firstname, Lastname, Email, Password);
}
`
The text was updated successfully, but these errors were encountered: