how do i get getUserInfo to work
n
how do i get getUserInfo to work
r
Hey!
n
yoo
i added the code it tells me to but it doesn't do anything
r
Frontend or backend?
n
both
i was thinking the front end function needs the backend endpoint for it to work? or no?
r
What’s the error?
And the frontend function doesn’t need the backend for it to work
n
theres no error theres just no data
r
Cause it reads it from the session tokens on the frontend
When you say no data, you mean the accessTokenPayload is empty?
n
okay
i mean when i print userId it says undefined
does this not work with https://try.supertokens.com?
r
On the frontend? On backend? Or both?
n
frontend
r
Can you print out the result of calling useSessionContext?
n
thats not even in the code is it?
i saw that in the youtube video but in the docs its not there
r
Are you referring to the reactjs tab on the frontend? Or which one?
n
reactjs frontend
r
Under the react js tab, there is a sub tab
n
oh im using no context
r
With session context
Ah right. Ok
I assume you were
Assumed*
Can you print out the value of await Session.getAccessTokenPayloadSecurely()
n
wait it works now
r
Hmm
n
okay it was because i thought i was pinging the backend endpoint
r
I don’t understand. What were you trying before?
n
i had the backend endpoint for getUserId
and i thought the frontend function was pinging for that
r
Hmm. You had created your own api on the backend for that?
n
like i added this
i forgot how to send code here lol
r
Three back ticks
n
Copy code
app.get("/get-user-info", verifySession(), async (req: SessionRequest, res) => {
    let userId = req.session!.getUserId();
    // You can learn more about the `User` object over here https://github.com/supertokens/core-driver-interface/wiki
    let userInfo = await ThirdPartyEmailPassword.getUserById(userId)
    // ... 
})
i added this to my backend
and i was returning userId
r
I see.
n
like res.send({userId: userId})
because i thought the frontend function was pinging for it
i thought i needed both for it to work
r
Oh I see
n
so i was trying to retrieve something
r
I can see how the docs structure would have made you think that
I guess I’ll make that page more clear somehow.
n
yeah because the other docs are usually you do all the steps in a row
r
Fair enough.
But yea I mean even if you had added that api, the function call should have worked anyway
So I’m not sure why userId was undefined earlier for you
n
oh because i wasn't actually doing a fetch to the endpoint
i thought this
Copy code
let userId = await Session.getUserId();
was doing the fetch to that endpoint
r
Hmm but this should have returned the userId to you anyway
Regardless of you having implemented that api on the backend
n
well i never pinged the endpoint
it was like this
i thought res would be userId lol
well it was a little different than that
but you get the point
r
Oh. Well you need to return something from getUserInfo function for res to have a value.
n
yeah it was different
r
Right okay
n
thats after i fixed it
r
Anyway, so it works now. Great
I’ll clarify in the docs. Thanks for free feedback
n
yeah thanks again
r
The*
17 Views