@graphcommerce/magento-customer 3.4.3 → 3.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts CHANGED
@@ -2,3 +2,5 @@ export * from './components'
2
2
  export * from './hooks'
3
3
 
4
4
  export * from './typePolicies'
5
+
6
+ export * from './link/createAuthLink'
@@ -0,0 +1,20 @@
1
+ import { ApolloCache, NormalizedCacheObject } from '@apollo/client'
2
+ import { setContext } from '@apollo/client/link/context'
3
+ import { CustomerTokenDocument } from '../hooks/CustomerToken.gql'
4
+
5
+ export const createAuthLink = (cache: ApolloCache<NormalizedCacheObject>) => {
6
+ return setContext((_, context) => {
7
+ if (!context.headers) context.headers = {}
8
+ try {
9
+ const query = cache.readQuery({ query: CustomerTokenDocument })
10
+ if (query?.customerToken?.token) {
11
+ context.headers.authorization = `Bearer ${query?.customerToken?.token}`
12
+ return context
13
+ } else {
14
+ return context
15
+ }
16
+ } catch (error) {
17
+ return context
18
+ }
19
+ })
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/magento-customer",
3
- "version": "3.4.3",
3
+ "version": "3.4.7",
4
4
  "sideEffects": false,
5
5
  "prettier": "@graphcommerce/prettier-config-pwa",
6
6
  "browserslist": [
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@apollo/client": "^3.4.16",
24
- "@graphcommerce/graphql": "^2.105.2",
24
+ "@graphcommerce/graphql": "^2.105.3",
25
25
  "@graphcommerce/image": "^2.105.2",
26
- "@graphcommerce/magento-graphql": "^2.104.2",
27
- "@graphcommerce/magento-store": "^3.2.3",
28
- "@graphcommerce/next-ui": "^3.12.3",
29
- "@graphcommerce/react-hook-form": "^2.102.14",
26
+ "@graphcommerce/magento-graphql": "^2.104.3",
27
+ "@graphcommerce/magento-store": "^3.2.7",
28
+ "@graphcommerce/next-ui": "^3.13.2",
29
+ "@graphcommerce/react-hook-form": "^2.103.0",
30
30
  "@graphql-typed-document-node/core": "^3.1.0",
31
31
  "@material-ui/core": "^4.12.3",
32
32
  "@material-ui/lab": "^4.0.0-alpha.60",
@@ -36,5 +36,5 @@
36
36
  "react": "^17.0.2",
37
37
  "react-dom": "^17.0.2"
38
38
  },
39
- "gitHead": "8fc77cf7261a01a54e82d2c9bdb2b59c31faeffc"
39
+ "gitHead": "db0c7ff1a81b75e4e6eeee3717a1fc608d9c3c86"
40
40
  }