bcrypt 散列加密问题 - node.js

Problems with bcrypt hash encryption - node.js

我在登录时遇到问题,hash,我在create方法中进行了调用,它工作正常,但在登录号中,我在堆栈上看到了与我的类似的错误,但我没有不懂怎么实现,能给个力吗? 它 returns 的错误消息是“错误:需要数据和哈希参数”错误所在的行将执行: 常量有效通行证

const connection = require('../database/connection');
const bcrypt = require('bcrypt');

async create(request, response){
        const {id, email, password, cpf, name, lastName, cellphone} = request.body;

        let salt = await bcrypt.genSaltSync(10);
        let hash = bcrypt.hashSync(password, salt);

        const newUser = await connection('login').insert({
            id,
            email,
            password:hash,
            cpf,
            name,
            lastName,
            cellphone,
        });
        return response.json({id: newUser[0], token: hash.toString('hex')});
        
    },

async login(request, response){
        const {email, password} = request.body;

        const user = await connection('login').first('*').where({email:email});

        if(user){
            const validPass = await bcrypt.compareSync(password, user.hash);
            if(validPass){
                response.status(200).json('valid Email and pass!');
            }else{
                response.json('Wrong pass!')
            }
        }else{
            response.status(400).json({error: 'No user foung with this E-mail'});
        }

        return response.json(user);
    }

这一行:

const validPass = await bcrypt.compareSync(password, user.hash);

user.hash 更改为 user.password

额外注意:在同步函数调用之前,您不需要那些等待。