context.passport.getUser() is not working on the client side
See original GitHub issueProblem:
context.passport.getUser()
is not working on the client side. When I login using the playground and then run the currentUser
query, I am returned the expected results, however, when I try to reproduce this on the client side using react and apollo client, I get back undefined.
Note, my previous ticket had similar issues with getting context.passport.isAuthenticated
to work client side. Not sure why this is working now but context.passport.getUser
isn’t working.
To Reproduce: for the backend:
- Clone this repo/branch
- Run
yarn
- Run
yarn build:dev
- In a second terminal, run
yarn run:dev
. - Login using the playground.
mutation {
login(email: "j@gmail.com", password: "abc") {
user {
id
firstName
lastName
email
}
}
}
- Run the
isAuthenticated
query. You should get the response oftrue
.
query {
isAuthenticated
}
- Run the
currentUser
query. You should get back an accurate response.
query{
currentUser{
email
firstName
lastName
}
}
for the frontend:
- Clone this repo/branch
- Run
yarn
- Run
yarn build:dev
- Run
yarn start
- The browser should open to
localhost:8080
. - Click the ‘login’ button, which will login using the same credentials as the playground.
- Click the ‘isAuthenticated’ button, which will confirm that you are authenticated.
- (make sure you have the dev console open) Click the ‘Current User’ button, which will perform the current user query. You will see in the console that undefined results are returned.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Node + Express + Passport: req.user Undefined - Stack Overflow
My issue was not specifying to send cookies when using fetch on the client-side. It worked after including the credentials: 'include' field in...
Read more >How to use getServerSideProps in a HOC for authentication
My problem is that I can find a way to make a HOC on which the ... You should only use "next/router" inside...
Read more >Simple Passport Local Authentication w/ React & Node.js
This is a simple, easy-to-understand, demystifying video about connecting React with Passport.js and creating a user authentication within a ...
Read more >Node.js and Express Tutorial: Authentication Using Passport
Learn how to use Passport.js to add user authentication to a web ... The client is server-side rendered using Pug templates styled with...
Read more >Authentication and authorization - Apollo GraphQL Docs
Try to retrieve a user with the token. 27. const user = await getUser(token);. 28. 29. // Add the user to the context....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey Jimmy. Sorry for missing this. Still don’t get notifications somehow. I’ll try to have a look tomorrow. Thanks for providing an example repo btw
I just needed to add
withCredentials: true
to my axios options 🤦♂️ apologies, should have probably posted this to stackoverflow instead.BTW, need to do this for React Suspense. It’s currently in beta but is pretty cool and would recommend checking it out if you’re curious.