feat: introduce authentication context

This commit is contained in:
Ali BARIN
2022-03-08 19:50:51 +01:00
committed by Ömer Faruk Aydın
parent 030d886cf7
commit 5d1c4b81e7
8 changed files with 103 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ import appConfig from 'config/app';
type CreateClientOptions = {
onError?: (message: string) => void;
token?: string | null;
};
const client = new ApolloClient({
@@ -12,8 +13,9 @@ const client = new ApolloClient({
link: createLink({ uri: appConfig.graphqlUrl })
});
export function setLink({ onError }: CreateClientOptions): typeof client {
const link = createLink({ uri: appConfig.graphqlUrl, onError });
export function setLink(options: CreateClientOptions): typeof client {
const { onError, token } = options;
const link = createLink({ uri: appConfig.graphqlUrl, token, onError });
client.setLink(link);