diff --git a/graphql/client/authLink.ts b/graphql/client/authLink.ts index 1ddd52ac1e56aaf1e542e281ee027efcd72ef481..ca27163a775606c541cbada97f5d8336e5eb28db 100644 --- a/graphql/client/authLink.ts +++ b/graphql/client/authLink.ts @@ -1,4 +1,5 @@ import { ApolloLink } from '@apollo/client' +import { onError } from '@apollo/client/link/error' const debounced = (fn: (msg: string) => void, delay: number) => { let timeout: NodeJS.Timeout @@ -13,15 +14,14 @@ const debounced = (fn: (msg: string) => void, delay: number) => { const authLink = (onFailedAuth: (msg: string) => void) => import.meta.env.VITE_NOAUTH === 'true' ? new ApolloLink((operation, forward) => forward(operation)) - : new ApolloLink((operation, forward) => - forward(operation).map(data => { - data.errors?.forEach(error => { - if (error.message === 'Authentication failed') { - debounced(onFailedAuth, 1000)('Authentication failed') - } - }) - return data + : onError(({graphQLErrors}) => { + if (graphQLErrors) { + graphQLErrors.forEach(error => { + if (error.message === 'Authentication failed') { + debounced(onFailedAuth, 1000)('Authentication failed') + } }) - ) + } + }) export default authLink