Skip to content

Instantly share code, notes, and snippets.

@SahanAmarsha
Created January 17, 2023 10:05
Show Gist options
  • Save SahanAmarsha/109b19385ce1311677ebf2bed1b9f101 to your computer and use it in GitHub Desktop.
Save SahanAmarsha/109b19385ce1311677ebf2bed1b9f101 to your computer and use it in GitHub Desktop.
Dashboard Layout Component
.
.
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