question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Where is the user object coming from?

See original GitHub issue

Hey guys, I’m currently studying nodejs, and this boilerplate is helping me a great deal. But I got stuck in one thing. See the code below to update an user

function update(req, res, next) {
  const user = req.user;
  user.username = req.body.username;
  user.mobileNumber = req.body.mobileNumber;

  user.save()
    .then(savedUser => res.json(savedUser))
    .catch(e => next(e));
}

Is the client supposed to send the entire user in the request? If not, how is the user embedded in the request?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
okononcommented, Dec 29, 2018

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.

1reaction
okononcommented, Dec 29, 2018

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Active Directory User Object: An Introduction
From the list of objects that appear in the menu, select User. An object creation wizard will appear.
Read more >
User | Object Reference for the Salesforce Platform
Forecast managers see forecast rollups from users below them in the forecast hierarchy. FullPhotoUrl. Type: url; Properties: Filter, Nillable, Sort; Description ...
Read more >
User Object - BidSwitch RTB Protocols
Each data object represents a different data source, for more information, see the Data Object section. For more information, see the User Ext...
Read more >
How to get the current logged in user object from spring ...
Returns the current user object. This can be User , UserDetails or your custom user object. You will need to cast the return...
Read more >
Document which properties are available in user objects.
Link new group page from relevant places, e.g. global $user doc (this might happen via an @ingroup tag, if those also apply to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found