-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CH-17: How do I create a new user without an existing one. No token = no user? #37
Comments
@ademars94 How did you fix this issue? |
@sahibjotsaggu You need to go into Like this: // POST to '/users' (token check happens AFTER this route, so it IS NOT protected)
apiRouter.route('/users')
.post({
// Create and save new user
})
// Route to obtain token
apiRouter.post('/authenticate', function(req, res) {
// Creates a token for valid user/password
}
// Route middleware to verify a token
apiRouter.use(function(req, res, next) {
// Checks for valid token on all requests AFTER THIS POINT
}
// GET user index (token check happens BEFORE this route, so it IS protected)
apiRouter.route('/users')
.get({
// Sends a response with the user index data
}) The reason you need to do this is because when you are trying to create a new user, you don't have an authentication token (since only users can get tokens). Protecting the route for creating new users makes no sense, so we move it before the token check / authentication logic. HOWEVER, you should keep the |
@sevilayha I am going to create a pull req for this issue, as I think this fix should be made. I remember having a very hard time figuring this out when I was doing the tutorial. |
@ademars94 Thanks for that! Ya, I figured that was the problem but I thought they would've thought about this when writing the book lol |
Fixed
The text was updated successfully, but these errors were encountered: