all repos — caroster @ 3010fd5066be948e41801643efc745089461e26a

[Octree] Group carpool to your event https://caroster.io

fix: :lock: Unauthenticate user on 401 gql response
Tim Izzo tim@octree.ch
Wed, 31 Aug 2022 09:07:08 +0000
commit

3010fd5066be948e41801643efc745089461e26a

parent

77a18fe2f9f1d973da32283784d93134a89a867a

1 files changed, 6 insertions(+), 8 deletions(-)

jump to
M frontend/lib/apolloClient.tsfrontend/lib/apolloClient.ts

@@ -29,15 +29,13 @@ },

}; }); -const errorLink = onError(({graphQLErrors = []}) => { - const [error] = graphQLErrors; - console.error({graphQLErrors}); +const errorLink = onError(error => { + const {networkError, graphQLErrors} = error; + console.error({networkError, graphQLErrors}); + const isUnauthorized = networkError?.response?.status === 401; - if ( - error?.message === 'Invalid token.' || - error?.message === 'User Not Found' || - error?.message === 'Your account has been blocked by the administrator.' - ) { + if (isUnauthorized) { + console.error('Unauthorized response received from GraphQL. Logout user.'); useAuthStore.getState().setToken(); useAuthStore.getState().setUser(); localStorage.removeItem('token');