Validate team on load and redirect if invalid
This commit is contained in:
1 parent
31f322630d
commit
a64f4e6dc6
1 file changed
+15
-3
+15
-3
@@ -5,7 +5,7 @@ import { useEffect } from 'react';
|
|||||||
import { MobileNav } from '@/app/(main)/MobileNav';
|
import { MobileNav } from '@/app/(main)/MobileNav';
|
||||||
import { SideNav } from '@/app/(main)/SideNav';
|
import { SideNav } from '@/app/(main)/SideNav';
|
||||||
import { TopNav } from '@/app/(main)/TopNav';
|
import { TopNav } from '@/app/(main)/TopNav';
|
||||||
import { useConfig, useLoginQuery, useNavigation } from '@/components/hooks';
|
import { useConfig, useLoginQuery, useNavigation, useTeamQuery } from '@/components/hooks';
|
||||||
import { LAST_TEAM_CONFIG } from '@/lib/constants';
|
import { LAST_TEAM_CONFIG } from '@/lib/constants';
|
||||||
import { removeItem, setItem } from '@/lib/storage';
|
import { removeItem, setItem } from '@/lib/storage';
|
||||||
import { UpdateNotice } from './UpdateNotice';
|
import { UpdateNotice } from './UpdateNotice';
|
||||||
@@ -13,7 +13,8 @@ import { UpdateNotice } from './UpdateNotice';
|
|||||||
export function App({ children }) {
|
export function App({ children }) {
|
||||||
const { user, isLoading, error } = useLoginQuery();
|
const { user, isLoading, error } = useLoginQuery();
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
const { pathname, teamId } = useNavigation();
|
const { pathname, router, teamId } = useNavigation();
|
||||||
|
const { isLoading: isTeamLoading, error: teamError } = useTeamQuery(teamId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (teamId) {
|
if (teamId) {
|
||||||
@@ -23,7 +24,14 @@ export function App({ children }) {
|
|||||||
}
|
}
|
||||||
}, [teamId]);
|
}, [teamId]);
|
||||||
|
|
||||||
if (isLoading || !config) {
|
useEffect(() => {
|
||||||
|
if (teamId && teamError) {
|
||||||
|
removeItem(LAST_TEAM_CONFIG);
|
||||||
|
router.replace('/');
|
||||||
|
}
|
||||||
|
}, [teamId, teamError, router]);
|
||||||
|
|
||||||
|
if (isLoading || !config || (teamId && isTeamLoading)) {
|
||||||
return <Loading placement="absolute" />;
|
return <Loading placement="absolute" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +46,10 @@ export function App({ children }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (teamId && teamError) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
columns={{ base: '1fr', lg: 'auto 1fr' }}
|
columns={{ base: '1fr', lg: 'auto 1fr' }}
|
||||||
|
|||||||
Reference in new issue
Block a user