0

authenticate: async(req,res) => {
    var email = req.body.email
    var password = req.body.password
    let emailAuth = await customer.email_auth(email) 
    // console.log(emailAuth[0].password)
    if(!emailAuth){
        return res.status(500).json({status: "Failed", message:"User not found"});
    }else if(emailAuth[0].password != password){
        return res.status(500).json({status: "Failed", message:"Authentication failed. Wrong password."});
    }else{
        const payload = {
            user : emailAuth[0].id
        };
        // console.log(payload)
        var token = jwt.sign(payload, app.get('superSecret'),{
            expiresIn: 3600 // 1menit
        });

        res.json({
            success: true,
            message: token,
        })
    }

}

|

1

0

authenticate: async(req,res) => {
    var email = req.body.email
    var password = req.body.password
    let emailAuth = await customer.email_auth(email) 
    // console.log(emailAuth[0].password)
    if(!emailAuth){
        return res.status(500).json({status: "Failed", message:"User not found"});
    }else if(emailAuth[0].password != password){
        return res.status(500).json({status: "Failed", message:"Authentication failed. Wrong password."});
    }else{
        const payload = {
            user : emailAuth[0].id
        };
        // console.log(payload)
        jwt.sign(payload, app.get('superSecret'),{expiresIn: 3600}, function(err, token){
            if(err){
                return res.json({success: false, message: err})
            }
            res.json({
                success: true,
                message: token,
            })
        });        
    }
}
|
  • ${token}