fix: stop flickering due to late initiated token

This commit is contained in:
Ali BARIN
2022-03-09 20:58:51 +01:00
parent 343b360303
commit 906a8d0644
4 changed files with 11 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ const client = new ApolloClient({
link: createLink({ uri: appConfig.graphqlUrl })
});
export function setLink(options: CreateClientOptions): typeof client {
export function mutateAndGetClient(options: CreateClientOptions): typeof client {
const { onError, token } = options;
const link = createLink({ uri: appConfig.graphqlUrl, token, onError });

View File

@@ -2,6 +2,7 @@ import { HttpLink, from } from '@apollo/client';
import type { ApolloLink } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
import { setItem } from 'helpers/storage';
import * as URLS from 'config/urls';
type CreateLinkOptions = {
@@ -29,6 +30,7 @@ const createErrorLink = (callback: CreateLinkOptions['onError']): ApolloLink =>
);
if (message === NOT_AUTHORISED) {
setItem('token', '');
window.location.href = URLS.LOGIN;
}
});