From 9c5a14298813f76f7b6ad109ba2b3a18fb550bce Mon Sep 17 00:00:00 2001
From: Jure Triglav <juretriglav@gmail.com>
Date: Sat, 15 Aug 2020 23:48:40 +0200
Subject: [PATCH] fix: redirect to login if token is no longer valid

---
 app/components/RolesUpdater.js | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/app/components/RolesUpdater.js b/app/components/RolesUpdater.js
index ea6240230c..8a20cb733e 100644
--- a/app/components/RolesUpdater.js
+++ b/app/components/RolesUpdater.js
@@ -1,7 +1,7 @@
-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
 }
 
-- 
GitLab