StartRedirect.tsx raw
1 import React from "react";
2 import { useLocation, useNavigate } from "react-router";
3 import Loading from "src/components/Loading";
4 import { useInfo } from "src/hooks/useInfo";
5
6 export function StartRedirect({ children }: React.PropsWithChildren) {
7 const { data: info } = useInfo();
8 const location = useLocation();
9 const navigate = useNavigate();
10
11 React.useEffect(() => {
12 if (info?.nodeMigrationFileCreated) {
13 // the hub is halted after creating a migration file and should not be
14 // used anymore, so keep showing the migration success instructions
15 navigate("/create-node-migration-file-success", { replace: true });
16 return;
17 }
18 if (!info || (info.setupCompleted && !info.running)) {
19 if (info && !info.albyAccountConnected && info.albyUserIdentifier) {
20 navigate("/alby/auth");
21 }
22 return;
23 }
24
25 navigate("/");
26 }, [info, location, navigate]);
27
28 if (!info) {
29 return <Loading />;
30 }
31
32 return children;
33 }
34