我正在try 在MongoDB中创建一个新用户,并希望为existing user
,但即使发送包含新用户详细信息的请求,它仍显示为User alreadyExists
export const signUp = async (req, res) => {
const {email, password, username, roomid} = req.body;
try {
console.log(req.body);
let existingUser = User.findOne({email});
console.log(existingUser);
if (existingUser) res.status(400).json({message: 'User already exists!!'});
const hashedPassword = await bcrypt.hash(password, 12);
const result = await User.create({
email,
password: hashedPassword,
username,
roomid,
});
const token = jwt.sign(
{email: existingUser.email, id: existingUser._id},
'test',
{expiresIn: '1hr'}
);
res.status(201).json({result, token});
} catch (err) {
console.log(err);
}
};
请帮帮忙
有人刚刚解决了创建新用户的问题