bcrypt.compare 给出 TypeError

问题描述 投票:0回答:1

我正在使用

Next.js v13.5.6
开展一个项目。 我正在使用
MongoDB Atlas
。我正在制作登录表单。我正在尝试执行登录操作。

我在使用 bcryptjs 时遇到了问题(

"bcryptjs": "^2.4.3"
)。

每当我使用此命令时:

const passwordsMatch = await bcrypt.compare(password, user.password);

它给了我这个错误:

TypeError: Cannot read properties of undefined (reading 'compare').

我已经检查了参数

password
(登录表单输入元素的值)和
user.password
(来自数据库的哈希密码)。 它们都有正确的期望值。 他们都是
string
类型。

我尝试过使用回调函数,但没有成功。 我尝试过使用

bcrypt.compareSync
,但没有成功。

authentication typeerror undefined next.js13 bcryptjs
1个回答
0
投票

尝试

import { compare } from 'bcrypt';
const passwordsMatch = await compare(password, user.password);
© www.soinside.com 2019 - 2024. All rights reserved.