From b54c85efaa34c5d8ade37c3a1171cc0fe2fcf0b9 Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Wed, 8 Jan 2020 21:55:37 +0100 Subject: [PATCH 1/2] Authorization: always use the most recent token value --- docs/source/tutorial/mutations.mdx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/source/tutorial/mutations.mdx b/docs/source/tutorial/mutations.mdx index e91060426..0dddeee0c 100644 --- a/docs/source/tutorial/mutations.mdx +++ b/docs/source/tutorial/mutations.mdx @@ -105,8 +105,10 @@ const client: ApolloClient = new ApolloClient({ link: new HttpLink({ uri: 'http://localhost:4000/graphql', headers: { - authorization: localStorage.getItem('token'), - }, + get authorization() { + return localStorage.getItem('token') + }, + }, }), }); @@ -123,7 +125,11 @@ cache.writeData({ const client = new ApolloClient({ cache, link: new HttpLink({ - headers: { authorization: localStorage.getItem('token') }, + headers: { + get authorization() { + return localStorage.getItem('token') + }, + }, uri: "http://localhost:4000/graphql", }), }); From 23b83ca0a1db10bcee4c075cb459c3a667bc83fe Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Wed, 8 Jan 2020 21:56:39 +0100 Subject: [PATCH 2/2] Update local-state.mdx --- docs/source/tutorial/local-state.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/tutorial/local-state.mdx b/docs/source/tutorial/local-state.mdx index 1c9b7dfbf..27a95b180 100644 --- a/docs/source/tutorial/local-state.mdx +++ b/docs/source/tutorial/local-state.mdx @@ -85,7 +85,9 @@ const client: ApolloClient = new ApolloClient({ link: new HttpLink({ uri: 'http://localhost:4000/graphql', headers: { - authorization: localStorage.getItem('token'), + get authorization() { + return localStorage.getItem('token') + }, }, }), typeDefs,