diff --git a/src/components/MoreMenu.tsx b/src/components/MoreMenu.tsx index be2496a..275ff98 100644 --- a/src/components/MoreMenu.tsx +++ b/src/components/MoreMenu.tsx @@ -1,11 +1,14 @@ import React from "react" import { useState } from "react" import { MdMoreVert } from "react-icons/md" +import { useHistory } from "react-router-dom" import { useOutsideClickRef } from "rooks" +import logout from "../functions/logout" import MoreMenuEntry from "./MoreMenuEntry" const MoreMenu: React.FC = () => { const [showMenu,setShowMenu] = useState(false) + const history = useHistory() const [outsideRef] = useOutsideClickRef(()=>{ setShowMenu(false) @@ -33,8 +36,10 @@ const MoreMenu: React.FC = () => { Menu 2 { + onclick={async ()=>{ setShowMenu(false) + await logout() + history.push("/login") }} > Logout diff --git a/src/functions/logout.ts b/src/functions/logout.ts new file mode 100644 index 0000000..52da74b --- /dev/null +++ b/src/functions/logout.ts @@ -0,0 +1,7 @@ +async function logout(): Promise { + await fetch("/api/logout",{ + method:"POST" + }) +} + +export default logout