это контроллер для регистрации пользователя
Код: Выделить всё
module.exports.loginUser = async (req, res) => {
const { email, password } = req.body;
const user = await userModel.findOne({ email }).select('+password');
if (!user) {
return res.status(400).json({ errors: [{ msg: 'invalid credentials' }] });
}
const isMatch = await user.comparePassword(password);
if (!isMatch) {
return res.status(400).json({ errors: [{ msg: 'invalid credentials' }] });
}
const token = await user.generateAuthToken();
return res.status(200).json({ token, user });
};
Подробнее здесь: https://stackoverflow.com/questions/797 ... userschema
Мобильная версия