Explore Library
Code QuizAdvanced

Verifying Passwords And Roles

Spot the bug in a login function that hashes and checks user roles.

Codejavascript
const bcrypt = require('bcrypt');

async function login(user, inputPassword) {
  // user.passwordHash was created earlier with bcrypt.hash(password, 10)
  const inputHash = await bcrypt.hash(inputPassword, 10);

  if (inputHash === user.passwordHash) {
    if (user.role === 'admin') {
      return 'admin dashboard';
    }
    return 'user dashboard';
  }
  return 'login failed';
}

What is the bug in this login function?