feat: add logout

This commit is contained in:
xion 2024-10-10 01:17:27 +08:00
parent 6b91b62ab9
commit 9a23521524
2 changed files with 17 additions and 3 deletions

View File

@ -7,15 +7,18 @@ import {
CodeOutlined, CodeOutlined,
DashboardOutlined, DashboardOutlined,
HomeOutlined, HomeOutlined,
LogoutOutlined,
MessageOutlined, MessageOutlined,
ReadOutlined, ReadOutlined,
RocketOutlined, RocketOutlined,
SmileOutlined, SmileOutlined,
SwapOutlined, SwapOutlined,
SwitcherOutlined, SwitcherOutlined,
UserOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { query } from '../query';
const meun = [ const meun = [
{ {
title: 'Your profile', title: 'Your profile',
@ -98,6 +101,17 @@ export const LayoutUser = () => {
); );
})} })}
</div> </div>
<div
className='flex items-center p-4 hover:bg-gray-100 cursor-pointer'
onClick={() => {
query.removeToken();
window.open('/user/login', '_self');
}}>
<div className='mr-4'>
<LogoutOutlined />
</div>
<div>Login Out</div>
</div>
</div> </div>
</div> </div>
); );

View File

@ -15,13 +15,13 @@ query.beforeRequest = async (config) => {
}; };
query.afterResponse = async (res) => { query.afterResponse = async (res) => {
if (res.code === 401) { if (res.code === 401) {
modal.setOpen(true);
}
if (res.code === 403) {
if (!res?.message) { if (!res?.message) {
message.error('Unauthorized'); message.error('Unauthorized');
} }
} }
if (res.code === 403) {
modal.setOpen(true);
}
return res; return res;
}; };
export const request = query.post; export const request = query.post;