我有以下
会话控制器.js
import User from '../models/User';
class SessionController {
async store(req, res) {
const { email, password } = req.body;
console.log(req.body);
const user = await User.findOne({ where: { email } });
}
}
export default new SessionController();
用户.js
import Sequelize, { Model } from 'sequelize';
import bcrypt from 'bcryptjs';
class User extends Model {
static init(sequelize) {
super.init(
{
name: Sequelize.STRING,
email: Sequelize.STRING,
password_hash: Sequelize.STRING,
},
{
sequelize,
}
);
return this;
}
checkPassword(password) {
return bcrypt.compare(password, this.password_hash);
}
}
export default User;
和 Insomnia 从 /sessions 路由发送数据
我打电话console.log(req.body),我得到了所有的数据,所以我不知道为什么我会收到这个错误:
(node:8589) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Function.findAll (/home/julio/www/bootcamp2019/gympoint/node_modules/sequelize/lib/model.js:1692:47)
at Function.findOne (/home/julio/www/bootcamp2019/gympoint/node_modules/sequelize/lib/model.js:1924:17)
at store (/home/julio/www/bootcamp2019/gympoint/src/app/controllers/SessionController.js:10:41)......
任何的想法?
蓝山帝景
侃侃尔雅
相关分类