'(React Router V6 & Amplify) I want it to go to the sign in page as soon as I start the project and I don't want to go to the home page without login [duplicate]

I have 2 problems.

  1. I want it to automatically redirect to /signin page when I start the project.
  2. I want to prevent someone who is not logged in from accessing the homepage.

I am using aws amplify for authentication and know there is no problem. I have no problem logging in. I want to use something like this Auth.currentSession ? (navigate = "/homepage") : (navigate = "/signin") Can you help me?

App.js

function App() {
  const ref = useRef(null);
  const navigate = useNavigate();
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/signin" element={<SignIn />}></Route>
        <Route path="/signup" element={<SignUp />}></Route>
        <Route path="/homepage" element={<HomePage />}></Route>
      </Routes>
    </BrowserRouter>
  );
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source