Open
Conversation
bwreid
commented
Aug 10, 2019
Collaborator
Author
bwreid
left a comment
There was a problem hiding this comment.
Overall, it's looking really good! Just a few of the routes are not quite working as expected.
| const schema = mongoose.Schema({ | ||
| username: String, | ||
| password: String, | ||
| admin: false |
Collaborator
Author
There was a problem hiding this comment.
I think you want this to be something like:
admin: {
type: Boolean,
default: false
}| const payload = jwt.verify(token, SECRET_KEY) | ||
| const user = await Users.findOne({ _id: payload.id }).select('-__v -password') | ||
| if (user.admin != true) throw new Error(`The JWT token is for a user who is not an admin ${jwtstatus}`) | ||
| if (!user) throw new Error(`User cannot be found ${nullUserStatus}`) |
Collaborator
Author
There was a problem hiding this comment.
You might want this error to go above the previous error. You'll always end up skipping this error, I believe, in the current case.
| if (!user) throw new Error(`User cannot be found ${nullUserStatus}`) | ||
|
|
||
| const {username, admin} = req.body | ||
| const userUpdate = await Users.findOne({username}) |
Collaborator
Author
There was a problem hiding this comment.
Instead, you should probably be searching for the user by the req.params.id.
| // const isAdmin = (user.admin === true) | ||
| // const adminStatus = 404 | ||
| // if(!isAdmin) throw new Error(`You do not have access ${adminStatus}`) | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
What was happening here that wasn't working? My guess would be the user.admin === true bit...?
| const payload = jwt.verify(token, SECRET_KEY) | ||
| const user = await Users.findOne({ _id: payload.id }).select('-__v -password') | ||
|
|
||
| const book = await Book.findById(id) |
Collaborator
Author
There was a problem hiding this comment.
Looks like this one still needs more work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.