Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: invalidate token on logout #191

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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