Skip to content

Tom Workman | WIP exercise-authentication-authorization Assignment#13

Open
tworkman512 wants to merge 8 commits intopce-uw-jscript400:masterfrom
tworkman512:master
Open

Tom Workman | WIP exercise-authentication-authorization Assignment#13
tworkman512 wants to merge 8 commits intopce-uw-jscript400:masterfrom
tworkman512:master

Conversation

@tworkman512
Copy link

No description provided.

Copy link
Collaborator

@bwreid bwreid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks on the right track! Just a few things left to do.

if (!checkForUser) throw new Error(`User ${username} does not exist.`);

const user = await bcrypt.compare(password, checkForUser.password);
if (!user) throw new Error(`Password is invalid.`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to keep these error messages the same, otherwise it's easier for someone to "guess" at a username. Having the same error message is more secure.

// const error = new Error("User cannot be found.");
// error.message = 404;
// return next(error);
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the order you have this in is a bit wrong. First you'll want to check for a user, then you'll want to check to see whether or not that user is an admin.

next(error)
console.error(e);
const message =
"Failure to create. Please check request body and try again.";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the right-hand assignment be on a different line works fine but looks a bit dicey.

const response = await Book.findById(book._id).select('-__v')
const status = 200
res.json({ status, response })
await book.save();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to include a user id as well when reserving a book.

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

Successfully merging this pull request may close these issues.

2 participants