Before saving user in database, you must hash the password.

Later on login, you will compare the plain password (provided by user) against the hashed password you saved in the database.

Create helper functions to hash and compare password using bcrypt library.

// helpers/auth.js
import bcrypt from "bcrypt";

export const hashPassword = (password) => {
  return new Promise((resolve, reject) => {
    bcrypt.genSalt(12, (err, salt) => {
      if (err) {
        reject(err);
      }
      bcrypt.hash(password, salt, (err, hash) => {
        if (err) {
          reject(err);
        }
        resolve(hash);
      });
    });
  });
};

export const comparePassword = (password, hashed) => {
  return bcrypt.compare(password, hashed);
};