Uncaught (in promise) Error: GraphQL error: Cannot read property 'id' of null
See original GitHub issueSteps to reproduce:
- Login as a new user (hasn’t entered their email yet)
- Select a trip from the home page
- Add trip to cart
- Go to cart
- Click Book All
It will explode with: Uncaught (in promise) Error: GraphQL error: Cannot read property ‘id’ of null.
Looking at the error more closely reveals that we are caching the guest user somewhere. The error comes back from
// src/datasources/user.js:35
const userId = this.context.user.id;
if (!userId) return;
This means the user context is null
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
How to fix "Cannot read property 'id' of null" error in javascript?
It looks like the user is not found. Try changing async bookTrips({ launchIds }) { const userId = this.context.user.id;. to
Read more >Cannot read properties of undefined (reading 'id') - TrackJS
In this case, our code expects to have an object with a id property, but that object was not present.
Read more >How to Avoid Getting 'Cannot read property of undefined' in ...
This error occurs when you try to read or access a property on an object that is undefined . Another common case that...
Read more >TypeError: cannot use 'in' operator to search for 'x' in 'y'
Make sure the object you are inspecting isn't actually null or undefined . const foo = null; "bar" in foo; // ...
Read more >TypeError: Cannot read property 'then' of undefined. Getting ...
[Solved]-TypeError: Cannot read property 'then' of undefined. Getting this error when I am trying to run updatefirst function-mongodb.
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 Free
Top 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
Same error here. Unable to execute the last part of the tutorial - on the server part. This is very disturbing when you want to learn a new piece of knowledge and you find yourself trying to solve a bug in a technology that by definition you don’t master yet.
Surprisingly this issue is still opened. According to Apollo Client own documentation authentication token should be handled this way: https://stackoverflow.com/questions/58556687/react-apollo-how-to-set-authorization-header-when-user-logs-in
(See first solution by Abderrahim Soubai Elidrissi)