@ -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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
import { useGetClientConfigQuery } from '~/generated/graphql';
|
||||
|
||||
export function useFetchClientConfig() {
|
||||
const { data } = useGetClientConfigQuery();
|
||||
|
||||
return data?.clientConfig;
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { useFetchClientConfig } from '@/auth/hooks/useFetchClientConfig';
|
||||
import { authProvidersState } from '@/client-config/states/authProvidersState';
|
||||
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
||||
import { isDemoModeState } from '@/client-config/states/isDemoModeState';
|
||||
import { telemetryState } from '@/client-config/states/telemetryState';
|
||||
import { useGetClientConfigQuery } from '~/generated/graphql';
|
||||
|
||||
export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
|
||||
children,
|
||||
@ -14,21 +14,33 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
|
||||
const [, setDebugMode] = useRecoilState(isDebugModeState);
|
||||
const [, setDemoMode] = useRecoilState(isDemoModeState);
|
||||
const [, setTelemetry] = useRecoilState(telemetryState);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const clientConfig = useFetchClientConfig();
|
||||
const { data, loading } = useGetClientConfigQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (clientConfig) {
|
||||
if (!loading) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
if (data?.clientConfig) {
|
||||
setAuthProviders({
|
||||
google: clientConfig.authProviders.google,
|
||||
password: clientConfig.authProviders.password,
|
||||
google: data?.clientConfig.authProviders.google,
|
||||
password: data?.clientConfig.authProviders.password,
|
||||
magicLink: false,
|
||||
});
|
||||
setDebugMode(clientConfig.debugMode);
|
||||
setDemoMode(clientConfig.demoMode);
|
||||
setTelemetry(clientConfig.telemetry);
|
||||
setDebugMode(data?.clientConfig.debugMode);
|
||||
setDemoMode(data?.clientConfig.demoMode);
|
||||
setTelemetry(data?.clientConfig.telemetry);
|
||||
}
|
||||
}, [clientConfig, setAuthProviders, setDebugMode, setDemoMode, setTelemetry]);
|
||||
}, [
|
||||
data,
|
||||
setAuthProviders,
|
||||
setDebugMode,
|
||||
setDemoMode,
|
||||
setTelemetry,
|
||||
setIsLoading,
|
||||
loading,
|
||||
]);
|
||||
|
||||
return <>{children}</>;
|
||||
return isLoading ? <></> : <>{children}</>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user