Skip to content

Commit

Permalink
fix(ui): improve auth error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Carlier committed Mar 29, 2022
1 parent 31136f9 commit aa55f48
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ui/src/contexts/GraphQLContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useCallback, useMemo } from 'react'
import { ApolloClient, ApolloProvider, from, HttpLink, InMemoryCache } from '@apollo/client'
import { ApolloClient, ApolloProvider, from, HttpLink, InMemoryCache, ServerError } from '@apollo/client'

import { API_BASE_URL } from '../constants'
import { setContext } from '@apollo/client/link/context'
Expand Down Expand Up @@ -35,9 +35,8 @@ const GraphQLProvider: FC = ({ children }) => {
return onError((err) => {
console.error(err)
if (err.networkError) {
const { name, message } = err.networkError
console.error('networkError:', name, message)
if (message === 'login_required' || message === 'invalid_grant') {
const { message } = err.networkError
if ((err.networkError as ServerError).statusCode === 401 || message === 'login_required' || message === 'invalid_grant') {
console.warn('redirecting to login page...')
login()
}
Expand Down

0 comments on commit aa55f48

Please sign in to comment.