Fix the code. Access should only be given to the users with the admin role.

Make sure that the user name is logged to the screen.

This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task

functions.js

import { checkAccess, grantAccess, denyAccess } from './helper.js';

export const auth = (user, password) => {
  if (checkAccess(user, password)) {
    grantAccess();
  } else {
    denyAccess();
  }
}

helper.js

export const checkAccess = (user, password) => {
  return user.password === password;
}

export const grantAccess = (name) => {
  console.log(`Congratulations, ${name}. Access granted.`)
}

export const denyAccess = (name) => {
  console.log(`Sorry, ${name}. Access denied.`)
}

solution.js

/**
 * Fix the code. Access should only be given to the users with the 'admin' role.
 * */

import { auth } from './functions.js';

const regularUser = {
  name: 'John',
  role: 'user',
  password: '123456'
};

const adminUser = {
  name: 'Sally',
  role: 'admin',
  password: 'BzL171a#*8!t'
};

console.log(`Authenticating ${regularUser}!`);
console.log(auth(regularUser, '123456'));

console.log(`Authenticating ${adminUser}!`);
console.log(auth(adminUser, 'BzL171a#*8!t'));