implemented login

This commit is contained in:
Djeeberjr 2021-09-18 19:33:31 +02:00
parent 02b43201b1
commit 4112fd795a
2 changed files with 13 additions and 1 deletions

View File

@ -1,11 +1,14 @@
import React from "react" import React from "react"
import { useState } from "react" import { useState } from "react"
import { MdMoreVert } from "react-icons/md" import { MdMoreVert } from "react-icons/md"
import { useHistory } from "react-router-dom"
import { useOutsideClickRef } from "rooks" import { useOutsideClickRef } from "rooks"
import logout from "../functions/logout"
import MoreMenuEntry from "./MoreMenuEntry" import MoreMenuEntry from "./MoreMenuEntry"
const MoreMenu: React.FC = () => { const MoreMenu: React.FC = () => {
const [showMenu,setShowMenu] = useState(false) const [showMenu,setShowMenu] = useState(false)
const history = useHistory()
const [outsideRef] = useOutsideClickRef(()=>{ const [outsideRef] = useOutsideClickRef(()=>{
setShowMenu(false) setShowMenu(false)
@ -33,8 +36,10 @@ const MoreMenu: React.FC = () => {
Menu 2 Menu 2
</MoreMenuEntry> </MoreMenuEntry>
<MoreMenuEntry <MoreMenuEntry
onclick={()=>{ onclick={async ()=>{
setShowMenu(false) setShowMenu(false)
await logout()
history.push("/login")
}} }}
> >
Logout Logout

7
src/functions/logout.ts Normal file
View File

@ -0,0 +1,7 @@
async function logout(): Promise<void> {
await fetch("/api/logout",{
method:"POST"
})
}
export default logout