Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 99032

Nodejs - UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object

$
0
0

I have the following

SessionController.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();

User.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;

And Insomnia to send data from /sessions route enter image description here

I call console.log(req.body) and I get all data, so I don't know why I'm getting this error:

(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)......

Any Idea?


Viewing all articles
Browse latest Browse all 99032

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>