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,
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 = () => {
);
})}
</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>
);

View File

@ -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;