Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/content/8/en/part8d.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,23 @@ const App = () => {
After the backend changes, creating new persons requires that a valid user token is sent with the request. In order to send the token, we have to change the way we define the *ApolloClient* object in <i>main.jsx</i> a little.

```js
import { ApolloClient, InMemoryCache, ApolloProvider, createHttpLink } from '@apollo/client' // highlight-line
import { setContext } from '@apollo/client/link/context' // highlight-line
import { ApolloClient, InMemoryCache, HttpLink, } from '@apollo/client' // highlight-line
import { ApolloProvider } from '@apollo/client/react'
import { SetContextLink } from '@apollo/client/link/context'

// highlight-start
const authLink = setContext((_, { headers }) => {
const authLink = new SetContextLink((preContext) => {
const token = localStorage.getItem('phonenumbers-user-token')
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : null,
}
...preContext.headers,
authorization: token ? `Bearer ${token}` : '',
},
}
})
// highlight-end

const httpLink = createHttpLink({
uri: 'http://localhost:4000',
})
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down