0

I'm building webapp using node and mongodb where i'm registering userdata in one api and getting jwt token as response and passing that token in another api and retrieving user data while doing that i'm able to get json object as response but .I'm getting undefined while i try to access one of the json object using . notation my response is printing like this

req.user is printing Object like below

{ "user": { "_id": "5f0082efe997800c40115be1", "name": "John Max", "email": "[email protected]" }, "iat": 1593869039 }

req.user._id gives undefined i tried accessing like this req.user[_id] as well nothing works ! where req.user is of type of object

1 Answer 1

1

without a clue on the code you used I'm probably wrong but :

  • If when you log "req.user" you get { "user": { "_id": "5f0082efe997800c40115be1", "name": "John Max", "email": "[email protected]" }, "iat": 1593869039 }, then you should access _id with : req.user.user._id (if I never saw this before I would'nt allow myself to suggest that ...)

  • Maybe it's an issue about parsing the json ?

Sign up to request clarification or add additional context in comments.

3 Comments

no @adzaria i have checked parsing json its working fine .and its of type object so json is parsed and printing fully but not able to access individual properties .
accessing like this works fine req.user.user._id .im able to get id can you explain how it works @adzaria
Hi ! I'm glad it works, actually you have stored your "user" object into another "user" object, without seeing your code it is hard to tell where it happens, but it's probably the way you store it the first time, if you post some code we can maybe check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.