feat: introduce authentication context
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
030d886cf7
commit
5d1c4b81e7
@@ -1,7 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import { ApolloProvider as BaseApolloProvider } from '@apollo/client';
|
||||
import { useSnackbar } from 'notistack';
|
||||
|
||||
import client, { setLink } from 'graphql/client';
|
||||
import useAuthentication from 'hooks/useAuthentication';
|
||||
|
||||
type ApolloProviderProps = {
|
||||
children: React.ReactNode;
|
||||
@@ -9,14 +11,15 @@ type ApolloProviderProps = {
|
||||
|
||||
const ApolloProvider = (props: ApolloProviderProps): React.ReactElement => {
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const authentication = useAuthentication();
|
||||
|
||||
const onError = React.useCallback((message) => {
|
||||
enqueueSnackbar(message, { variant: 'error' });
|
||||
}, [enqueueSnackbar]);
|
||||
|
||||
React.useEffect(() => {
|
||||
setLink({ onError })
|
||||
}, [onError]);
|
||||
setLink({ onError, token: authentication.token })
|
||||
}, [onError, authentication]);
|
||||
|
||||
return (
|
||||
<BaseApolloProvider client={client} {...props} />
|
||||
|
Reference in New Issue
Block a user