redirecting to login if not authenticated in router
This commit is contained in:
parent
e639e2cdf9
commit
e17896aa35
2 changed files with 21 additions and 3 deletions
|
|
@ -2,11 +2,13 @@ import { Suspense } from "react";
|
|||
import LoadingScreen from "../app/LoadingScreen";
|
||||
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
|
||||
import { Typography } from "@mui/material";
|
||||
import { useAuth0 } from "@auth0/auth0-react";
|
||||
|
||||
|
||||
|
||||
export default function Router() {
|
||||
|
||||
const { isAuthenticated, loginWithRedirect, isLoading } = useAuth0()
|
||||
|
||||
const hello = () => {
|
||||
return (
|
||||
|
|
@ -16,6 +18,21 @@ export default function Router() {
|
|||
)
|
||||
}
|
||||
|
||||
// useEffect(() => {
|
||||
// setAuthorized(isAuthenticated || offline);
|
||||
// if (isAuthenticated && !user.empty() && !user.status.finishedIntro) {
|
||||
// history.push("/welcome");
|
||||
// }
|
||||
// }, [history, isAuthenticated, offline, user]);
|
||||
|
||||
if (isLoading) return null;
|
||||
if (!isAuthenticated) {
|
||||
loginWithRedirect()
|
||||
return (
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Suspense fallback={<LoadingScreen />}>
|
||||
<BrowserRouter>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue