Fix authentication with debug mode (#532)

Fix authent with debug mode
This commit is contained in:
Charles Bochet
2023-07-07 14:10:04 -07:00
committed by GitHub
parent c847bca293
commit f62fdc1219
4 changed files with 30 additions and 26 deletions

View File

@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef } from 'react';
import { useMemo, useRef } from 'react';
import {
ApolloLink,
InMemoryCache,
@ -67,16 +67,11 @@ export function useApolloFactory() {
},
extraLinks: isMockMode ? [mockLink] : [],
isDebugMode,
tokenPair,
});
return apolloRef.current.getClient();
}, [isMockMode, setTokenPair, isDebugMode]);
useEffect(() => {
if (apolloRef.current) {
apolloRef.current.updateTokenPair(tokenPair);
}
}, [tokenPair]);
}, [isMockMode, setTokenPair, isDebugMode, tokenPair]);
return apolloClient;
}

View File

@ -30,6 +30,7 @@ export interface Options<TCacheShape> extends ApolloClientOptions<TCacheShape> {
onUnauthenticatedError?: () => void;
extraLinks?: ApolloLink[];
isDebugMode?: boolean;
tokenPair: AuthTokenPair | null;
}
export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
@ -45,9 +46,12 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
onUnauthenticatedError,
extraLinks,
isDebugMode,
tokenPair,
...options
} = opts;
this.tokenPair = tokenPair;
const buildApolloLink = (): ApolloLink => {
const httpLink = createHttpLink({
uri,

View File

@ -1,7 +0,0 @@
import { useGetClientConfigQuery } from '~/generated/graphql';
export function useFetchClientConfig() {
const { data } = useGetClientConfigQuery();
return data?.clientConfig;
}