Skip to content

auth exercise#21

Open
wedge1126 wants to merge 1 commit into
pce-uw-jscript400:masterfrom
wedge1126:master
Open

auth exercise#21
wedge1126 wants to merge 1 commit into
pce-uw-jscript400:masterfrom
wedge1126:master

Conversation

@wedge1126

Copy link
Copy Markdown

No description provided.

@bwreid bwreid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Excellent work as always, Jonathan.

Comment thread api/routes/auth.js
const hash = await bcrypt.hash(password, 12)
// create a new user with the hashed password
const response = await User.create({ username: username, password: hash })
const payload = { id: response._id, username: response.username, admin: response.admin }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Destructuring the response above can be an easy way to make this code a bit more readable.

Comment thread api/routes/books.js
payload = jwt.verify(token, SECRET_KEY)
} catch (e) {
return next({ status: 401, message: 'Invalid token.' })
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would encourage you to move this into middleware.

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