how to make login logic ( using Sequelize )


login proc that i thought is…

  1. put nickname, User_pw in req.body.
  2. using findByPk, check specific data.
  3. if User_pw in data is same with req.body.User_pw,
    login success.

can i using this logic?
how to use found data?
( like… if i found data using findByPk, i wanna compare User_pw in data with req.body.User_pw )

this is code…

>'/login', function(req,res,next){  
  var nickname = req.body.nickname  
  var User_pw = req.body.User_pw  
  db.Normal_user.findByPk(nickname).then((res) => {  
  }).catch((err) => {  
      success : false  
    }), console.log(err)  


You can search for the row where both, username and password, are the ones inserted.
In this case, you can simply check if you get any user. If you don’t get any, it means that there is no user with the received username and password and you can return an message like: Username or password incorrect'/login', async(req,res,next){  
  var nickname = req.body.nickname  
  var User_pw = req.body.User_pw  
  const user = await db.Normal_user.findOne({
    where: {
      nickname: nickname,
      User_pw: User_pw
        success: false
        success: true

Answered By – Alexandru DuDu

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.