@trackunit/react-core-contexts 0.4.162 → 0.4.164

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.
Files changed (3) hide show
  1. package/index.cjs +6 -1
  2. package/index.js +7 -2
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -167,12 +167,17 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
167
167
  const useApolloClient = (isIrisApp) => {
168
168
  var _a;
169
169
  const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = reactCoreHooks.useEnvironment();
170
+ const { tasUserId } = reactCoreHooks.useCurrentUser();
170
171
  const { token } = reactCoreHooks.useToken();
172
+ const tasUserIdRef = React__namespace.useRef();
171
173
  const clientRef = React__namespace.useRef(null);
174
+ if (!tasUserIdRef.current) {
175
+ tasUserIdRef.current = tasUserId;
176
+ }
172
177
  /* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
173
178
  the token will then be set on the instance without react reporting a new client
174
179
  and recreating if token change from null to something*/
175
- if (!clientRef.current || !clientRef.current.getToken()) {
180
+ if (!clientRef.current || !clientRef.current.getToken() || tasUserIdRef.current !== tasUserId) {
176
181
  clientRef.current = createApolloClient({
177
182
  graphqlManagerUrl,
178
183
  graphqlPublicUrl,
package/index.js CHANGED
@@ -3,7 +3,7 @@ import { ApolloProvider, ApolloClient, InMemoryCache, from, split } from '@apoll
3
3
  import { setContext } from '@apollo/client/link/context';
4
4
  import { onError } from '@apollo/client/link/error';
5
5
  import * as Sentry from '@sentry/browser';
6
- import { useEnvironment, useToken, ToastProvider, AnalyticsContextProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, OemBrandingContextProvider as OemBrandingContextProvider$1, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
6
+ import { useEnvironment, useCurrentUser, useToken, ToastProvider, AnalyticsContextProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, OemBrandingContextProvider as OemBrandingContextProvider$1, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
7
7
  import { createUploadLink } from 'apollo-upload-client';
8
8
  import * as React from 'react';
9
9
  import { useMemo, useEffect, useState } from 'react';
@@ -143,12 +143,17 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
143
143
  const useApolloClient = (isIrisApp) => {
144
144
  var _a;
145
145
  const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = useEnvironment();
146
+ const { tasUserId } = useCurrentUser();
146
147
  const { token } = useToken();
148
+ const tasUserIdRef = React.useRef();
147
149
  const clientRef = React.useRef(null);
150
+ if (!tasUserIdRef.current) {
151
+ tasUserIdRef.current = tasUserId;
152
+ }
148
153
  /* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
149
154
  the token will then be set on the instance without react reporting a new client
150
155
  and recreating if token change from null to something*/
151
- if (!clientRef.current || !clientRef.current.getToken()) {
156
+ if (!clientRef.current || !clientRef.current.getToken() || tasUserIdRef.current !== tasUserId) {
152
157
  clientRef.current = createApolloClient({
153
158
  graphqlManagerUrl,
154
159
  graphqlPublicUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.4.162",
3
+ "version": "0.4.164",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {