From 9a2352152407fab0bff33e9f27b33824639e40ee Mon Sep 17 00:00:00 2001 From: xion Date: Thu, 10 Oct 2024 01:17:27 +0800 Subject: [PATCH] feat: add logout --- src/modules/layout/LayoutUser.tsx | 14 ++++++++++++++ src/modules/query.ts | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/layout/LayoutUser.tsx b/src/modules/layout/LayoutUser.tsx index d8a086e..25efc34 100644 --- a/src/modules/layout/LayoutUser.tsx +++ b/src/modules/layout/LayoutUser.tsx @@ -7,15 +7,18 @@ import { CodeOutlined, DashboardOutlined, HomeOutlined, + LogoutOutlined, MessageOutlined, ReadOutlined, RocketOutlined, SmileOutlined, SwapOutlined, SwitcherOutlined, + UserOutlined, } from '@ant-design/icons'; import { useNavigate } from 'react-router'; import { useMemo } from 'react'; +import { query } from '../query'; const meun = [ { title: 'Your profile', @@ -98,6 +101,17 @@ export const LayoutUser = () => { ); })} +
{ + query.removeToken(); + window.open('/user/login', '_self'); + }}> +
+ +
+
Login Out
+
); diff --git a/src/modules/query.ts b/src/modules/query.ts index 1e15221..38f14da 100644 --- a/src/modules/query.ts +++ b/src/modules/query.ts @@ -15,13 +15,13 @@ query.beforeRequest = async (config) => { }; query.afterResponse = async (res) => { if (res.code === 401) { + modal.setOpen(true); + } + if (res.code === 403) { if (!res?.message) { message.error('Unauthorized'); } } - if (res.code === 403) { - modal.setOpen(true); - } return res; }; export const request = query.post;