Skip to content

WIP still working on books route#11

Open
oieeri26 wants to merge 9 commits intopce-uw-jscript400:masterfrom
oieeri26:master
Open

WIP still working on books route#11
oieeri26 wants to merge 9 commits intopce-uw-jscript400:masterfrom
oieeri26:master

Conversation

@oieeri26
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.

This is really well done, Erik!

const user = await User.findOne({
username
})
if (user) throw new Error(`Username ${username} already taken.`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might move the above few lines below your validation for username and password. That way, if the username is not long enough, you will throw an error earlier. Right now, you'll make an unnecessary call to the database if that's the case.

}
if (!book) throw new Error(`Request body failed: ${JSON.stringify(req.body)}`)

if (token && checkAdmin.admin) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

At this point, I think you just need checkAdmin.admin.

if (!payload) {
const error = new Error(`A valid JWT token is not provided.`)
error.status = 401
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 would add return statements next to these next() calls.

const users = await User.create([
{
username: "user",
password: "$2b$10$uudM8Q/k8qXrsW99Puwj.evV.0maEhkh2f68/RYcCLdmmmyy7SANS"
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could just include bcrypt in this file, and then do bcrypt.hashSync() or the equivalent.

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