Skip to content
Snippets Groups Projects
Commit 9c5a1429 authored by Jure's avatar Jure
Browse files

fix: redirect to login if token is no longer valid

parent acf6fbe6
No related branches found
No related tags found
No related merge requests found
import { useCallback } from 'react'
import React, { useCallback } from 'react'
import { useQuery } from '@apollo/client'
import { Redirect } from 'react-router-dom'
import { GET_CURRENT_USER } from '../queries'
import currentRolesVar from '../shared/currentRolesVar'
const updateStuff = data => {
......@@ -12,13 +12,18 @@ const updateStuff = data => {
const RolesUpdater = ({ children, history, match }) => {
// This updates the current roles app-wide using Apollo's makeVar
useQuery(GET_CURRENT_USER, {
const { error } = useQuery(GET_CURRENT_USER, {
pollInterval: 5000,
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
// TODO: useCallback used because of bug: https://github.com/apollographql/apollo-client/issues/6301
onCompleted: useCallback(data => updateStuff(data), []),
})
if (error && !error.networkError) {
return <Redirect to="/login" />
}
return null
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment