Skip to content

Commit

Permalink
feat: invalidate token on logout (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHenry35 authored Aug 4, 2024
1 parent 2ed8d32 commit 7e3bef7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/pages/manage/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ import {
import { TiThMenu } from "solid-icons/ti"
import { IoExit } from "solid-icons/io"
import { SwitchColorMode, SwitchLanguageWhite } from "~/components"
import { useRouter, useT } from "~/hooks"
import { useFetch, useRouter, useT } from "~/hooks"
import { SideMenu } from "./SideMenu"
import { side_menu_items } from "./sidemenu_items"
import { changeToken, notify } from "~/utils"
import { changeToken, handleResp, notify, r } from "~/utils"
import { PResp } from "~/types"
const { isOpen, onOpen, onClose } = createDisclosure()
const [logOutReqLoading, logOutReq] = useFetch(
(): PResp<any> => r.get("/auth/logout"),
)

const Header = () => {
const t = useT()
const { to } = useRouter()
const logOut = async () => {
handleResp(await logOutReq(), () => {
changeToken()
notify.success(t("manage.logout_success"))
to(`/@login?redirect=${encodeURIComponent(location.pathname)}`)
})
}
return (
<Box
as="header"
Expand Down Expand Up @@ -64,11 +75,8 @@ const Header = () => {
<IconButton
aria-label="logout"
icon={<IoExit />}
onClick={() => {
changeToken()
notify.success(t("manage.logout_success"))
to(`/@login?redirect=${encodeURIComponent(location.pathname)}`)
}}
loading={logOutReqLoading()}
onClick={logOut}
size="sm"
/>
</HStack>
Expand Down

0 comments on commit 7e3bef7

Please sign in to comment.