Using jsonwebtoken always prompts that the parameters are wrong, and if you bring up the parameters and declare them with a single variable, you will not report an error. What is the reason for this?

// keys.js
module.exports = {
    mongoURI: "",
    secretOrKey: "secret"
}
const keys = require("../../config/keys");

router.post("/login", (req, res) => {
    const email = req.body.email;
    const password = req.body.password;
    
    User.findOne({ email }).then(user => {
        if (!user) {
            return res.status(404).json({ email: "!" })
        }

        // Load hash from your password DB.
        bcrypt.compare(password, user.password, (err, isMatch)=>{
            if(isMatch){
                const rule = {id:user.id,name:user.name};
                jwt.sign({rule, keys.secretOrKey, {expiresIn:3600}, (err,token)=>{
                    if(err)throw err;
                    res.json({
                        success:true,
                        token:"partiny"+token
                    });
                }});                
                res.json({msg:"success"});
            }else{
                return res.status(400).json({password:""});
            }
        });
    })
})

clipboard.png

Apr.15,2022

jwt.sign(rule, keys.secretOrKey, {expiresIn:3600}, (err,token)=>{
    if(err)throw err;
    res.json({
        success:true,
        token:"partiny"+token
    });
});

write two more parentheses:
clipboard.png

rule is preceded by a parenthesis, which means you pass an object to the sign function:

let a = {rule} //  let a = {rule: rule}
// 
let a = {rule, keys.secretOrKey} // let a = {rule: rule, keys.secretOrKey: keys.secretOrKey}?
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e1bc-2c3dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e1bc-2c3dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?