authorization header
See original GitHub issueHi
Why I can’t use localStorage
in withApollo.js
?
I run this code:
import withApollo from 'next-with-apollo';`
import ApolloClient, { InMemoryCache } from 'apollo-boost';
import { ApolloProvider } from '@apollo/react-hooks';
export default withApollo(
({ initialState }) => {
return new ApolloClient({
uri: 'http://localhost:8000/graphql/',
cache: new InMemoryCache().restore(initialState || {}),
headers: {
authorization: localStorage.getItem("token")
}
});
},
{
render: ({ Page, props }) => {
return (
<ApolloProvider client={props.apollo}>
<Page {...props} />
</ApolloProvider>
);
}
}
);
and I see this error:
ReferenceError: localStorage is not defined module.exports../lib/withApollo.js.__webpack_exports__.default.next_with_apollo__WEBPACK_IMPORTED_MODULE_1___default.render.Page.Page ./lib/withApollo.js:11
Can you help me?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >Basic access authentication - Wikipedia
In basic HTTP authentication, a request contains a header field in the form of Authorization: Basic <credentials> , where credentials is the Base64...
Read more >Http authorization header entity definition - Microsoft Learn
An authorization header used in HTTP request. Pattern. Various authentication header formats for example: authorization: basic ********
Read more >HTTP headers | Authorization - GeeksforGeeks
The HTTP headers Authorization header is a request type header that used to contains the credentials information to authenticate a user ...
Read more >Bearer Authentication - Swagger
The client must send this token in the Authorization header when making requests to protected resources: Authorization: Bearer <token>.
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
localStorage is only client side so it’s undefined server side
Yes, It works for SSR but I didn’t want to use my token in ApolloClient. I think (and I hope) it works in ApolloClient, too.