Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcrypt import return undefined #161

Open
apudiu opened this issue Feb 25, 2025 · 2 comments
Open

bcrypt import return undefined #161

apudiu opened this issue Feb 25, 2025 · 2 comments

Comments

@apudiu
Copy link

apudiu commented Feb 25, 2025

In nest.js project

import bcrypt from 'bcryptjs';

export class AuthService {

// .....

  private async validateUser(dto: SignInDto): Promise<User | null> {
      console.log('------------->');
      console.dir(bcrypt);
      // compare password
      const isValidPassword = await bcrypt.compare(dto.data.password, user.password);
      if (!isValidPassword) return null;

      return user;
    }

}

In console

------------->
undefined
POST /api/auth/login 500 in 21ms
[Nest] 1938  - 02/25/2025, 5:16:48 AM   ERROR [ExceptionsHandler] TypeError: Cannot read properties of undefined (reading 'compare')
     at AuthService.validateUser (/usr/src/app/src/auth/auth.service.ts:133:42)

What could be the issue?

@leontm-dev
Copy link

I've got the same issue

Package version: 3.0.2

@leontm-dev
Copy link

You can just import the functions one by one so:
import { compareSync, hash, hashSync, ... } from 'bcryptjs';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants