diff --git a/hooks/useUser.js b/hooks/useUser.js index 81900982..27d265c4 100644 --- a/hooks/useUser.js +++ b/hooks/useUser.js @@ -14,7 +14,6 @@ export const UserProvider = ({ children }) => { const [user, setUser] = useState() const [error, setError] = useState() const [loading, setLoading] = useState(true) - // const [loadingInitial, setLoadingInitial] = useState(true) const getUser = () => { return getAPI(apiEndpoints.ACCOUNT_METADATA) diff --git a/pages/incidents/dashboard.js b/pages/incidents/dashboard.js index 405e4acc..a45233de 100644 --- a/pages/incidents/dashboard.js +++ b/pages/incidents/dashboard.js @@ -34,7 +34,7 @@ const StyledRow = styled.tr` const IncidentsDashboard = () => { const intl = useIntl() - const { user } = useUser() + const { user, loading } = useUser() const router = useRouter() const { data, error } = useSWR(apiEndpoints.SEARCH_INCIDENTS, fetcher) @@ -45,8 +45,8 @@ const IncidentsDashboard = () => { // redirect non-admin users useEffect(() => { - if (user && user?.role !== 'admin') router.replace('/incidents') - }, [user, router]) + if (!loading && user?.role !== 'admin') router.replace('/incidents') + }, [user, loading, router]) const columns = useMemo( () => [