Skip to content

Commit

Permalink
fix: switch project
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed Sep 16, 2024
1 parent 6c26abf commit 89dc8da
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/react-ui/src/app/router/project-route-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ const TokenCheckerWrapper: React.FC<{ children: React.ReactNode }> = ({
const { projectId } = useParams<{ projectId: string }>();
const currentProjectId = authenticationSession.getProjectId();
const { toast } = useToast();
const { data, isError, isLoading } = useQuery<string | null, Error>({
const { data: isProjectValid, isError } = useSuspenseQuery<boolean, Error>({
queryKey: ['switch-to-project', projectId],
queryFn: async () => {
if (isNil(projectId)) {
return false;
}
try {
await authenticationSession.switchToSession(projectId!);
return projectId!;
return true;
} catch (error) {
if (api.isError(error)) {
toast({
Expand All @@ -31,19 +34,18 @@ const TokenCheckerWrapper: React.FC<{ children: React.ReactNode }> = ({
});
authenticationSession.clearSession();
}
return null;
return false;
}
},
retry: false,
staleTime: Infinity,
enabled: !!projectId,
});

if (isNil(currentProjectId) || isNil(projectId)) {
return <Navigate to="/sign-in" replace />;
}

if (isError || (isNil(data) && !isLoading)) {
if (isError || !isProjectValid) {
return <Navigate to="/404" replace />;
}

Expand Down

0 comments on commit 89dc8da

Please sign in to comment.