Created
January 17, 2023 10:05
-
-
Save SahanAmarsha/109b19385ce1311677ebf2bed1b9f101 to your computer and use it in GitHub Desktop.
Dashboard Layout Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
import LoadingSpinner from "./LoadingSpinner"; | |
import useAuth from "../hooks/useAuth"; | |
. | |
. | |
const DashboardLayout = () => { | |
const navigate = useNavigate(); | |
const [open, setOpen] = React.useState(true); | |
const { isAuthenticating, isAuthenticated, signOut } = useAuth(); | |
. | |
. | |
const handleLogout = async () => { | |
try { | |
// sign out user | |
await signOut(); | |
await navigate("/signin", { replace: true }); | |
} catch (err) { | |
console.error("Auth Error: ", err); | |
} | |
}; | |
useEffect(() => { | |
if (isAuthenticating || !isAuthenticated) { | |
navigate("/signin", { replace: true }); | |
} | |
}, [isAuthenticating, isAuthenticated]); | |
if (isAuthenticating || !isAuthenticated) { | |
return <LoadingSpinner />; | |
} | |
return ( | |
. | |
. | |
); | |
}; | |
export default DashboardLayout; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment