I'm working on a project using Next.js v14.0.0
.
I'm using MongoDB Atlas
. I'm working on a login form. I'm trying to perform a login operation.
I've been experiencing a problem, when using bcryptjs ("bcryptjs": "^2.4.3"
).
Whenever I use this command:
const passwordsMatch = await bcrypt.compare(password, user.password);
It gives me this error:
TypeError: Cannot read properties of undefined (reading 'compare').
I've checked the arguments password
(the value from the input element of the login form) and user.password
(the hashed password, from the database).
They both have the right expected values.
They are both of type string
.
I've tried to use callback function, with no sucess.
I've tried to use bcrypt.compareSync
, with no sucess.
try
import { compare } from 'bcrypt';
const passwordsMatch = await compare(password, user.password);