Skip to content

Commit 2f663a4

Browse files
authored
Fix some errors on configuring-graphql-client-for-user-session.md (#893)
Some typos and errors with Apollo Link examples
1 parent d7a2ba3 commit 2f663a4

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/configuring-graphql-client-for-user-session.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ And that's our callback for applying the our session token to each request made
107107
import { ApolloLink } from '@apollo/client';
108108

109109
const consoleLink = new ApolloLink((operation, forward) => {
110-
return operation.setContext(/* our callback */);
110+
operation.setContext(/* our callback */);
111+
return forward(operation);
111112
});
112113
```
113114

@@ -294,7 +295,7 @@ Next, define the `createUpdateLink` function as follows:
294295
```javascript
295296
import { setContext } from '@apollo/client/link/context';
296297

297-
function createUpdateLink(operation, forward) => {
298+
function createUpdateLink(operation, forward) {
298299
return forward(operation).map((response) => {
299300
/**
300301
* Check for session header and update session in local storage accordingly.
@@ -303,10 +304,8 @@ function createUpdateLink(operation, forward) => {
303304
const { response: { headers } } = context;
304305
const oldSessionToken = localStorage.getItem(process.env.SESSION_TOKEN_LS_KEY as string);
305306
const sessionToken = headers.get('woocommerce-session');
306-
if (sessionToken) {
307-
if ( oldSessionToken !== session ) {
308-
localStorage.setItem(process.env.SESSION_TOKEN_LS_KEY as string, sessionToken);
309-
}
307+
if (sessionToken && sessionToken !== oldSessionToken) {
308+
localStorage.setItem(import.meta.env.PUBLIC_SESSION_TOKEN_LS_KEY as string, sessionToken);
310309
}
311310

312311
return response;

0 commit comments

Comments
 (0)