Comments (6)
few.user is not what you want. It is an object which contains information that was encoded in JWT and got decided after successfull JWT validation.
Client should send user information in req.body
And you should:
- Select user from database fires to see if user exists
- update user that you selected in previous step with information from req.body
- save user to database
from express-mongoose-es6-rest-api.
First check if the route that your update function is tied to is protected with JWT. If yes then you will get req.user automatically if client (Postman) sends requests with valid Authorization token (you get this token from auth endpoint)
Usually this req.user object is for checking JWT decoded info.
I think you are confusing it with user records stored in the database.
from express-mongoose-es6-rest-api.
@okonon Ok tnx man. So I have to first have a succesful login through JWT so I can update the user, is that it? Can I test this using Postman?
from express-mongoose-es6-rest-api.
User routes are not protected. So I think you will not get req.user object at all.
from express-mongoose-es6-rest-api.
@okonon exactly, it is not protected. This is very confusing. How come no one noticed until now? Maybe we are missing something. This should be more clear in the documentation.
from express-mongoose-es6-rest-api.
see example pseudoscode below wrote it on my phone so I do not know if this actual code will work and I apologize for formatting
const user = User.findById(req.params.userId).then((user) => {
//update user here
user.username = req.body.username;
user.mobileNumber = req.body.mobileNumber;
user.save()
.then(savedUser => res.json(savedUser))
.catch(e => next(e));
})
from express-mongoose-es6-rest-api.
Related Issues (20)
- Migrate from mocha to jest
- Use mongodb in-memory server for tests
- How to Join these two documents for API calls HOT 1
- (err instanceof APIError) always returning false HOT 4
- What is the reason of removing babel and gulp? HOT 1
- Dockerfile doesn't account for Mongo at all HOT 1
- bodyParser: unable to obtain form-data from post request.
- joi error: Cannot send HTTP-status [422] while joi validation is failed
- Yarn build not working anymore HOT 5
- Converting mobile number to password
- What is the benifit of ExtendableError? HOT 2
- Why I don't see my changes when I modify code HOT 4
- getting this error when I run - yarn test:coverage HOT 1
- yarn build doens't exist - how does one build the app?
- getting the below error after npm start HOT 1
- Misleading docs about nodemon HOT 1
- How to server static files? HOT 1
- https setup
- Project status?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-mongoose-es6-rest-api.