提交 b96ccbb2 作者: ZhangLingKun

功能:登录问题修复

上级 9aa1dd84
...@@ -11,7 +11,7 @@ const service = axios.create({ ...@@ -11,7 +11,7 @@ const service = axios.create({
service.interceptors.request.use( service.interceptors.request.use(
(config: any) => { (config: any) => {
const token = Cookies.get('SHAREFLY-TOKEN'); const token = Cookies.get('SHAREFLY-WEB-TOKEN');
// console.log('config ==========>', config); // console.log('config ==========>', config);
if (token) { if (token) {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
...@@ -40,7 +40,7 @@ service.interceptors.response.use( ...@@ -40,7 +40,7 @@ service.interceptors.response.use(
) )
) { ) {
message.error(data.message).then(); message.error(data.message).then();
Cookies.remove('SHAREFLY-TOKEN'); Cookies.remove('SHAREFLY-WEB-TOKEN');
localStorage.removeItem('persist:SHAREFLY-WEB-STORAGE'); localStorage.removeItem('persist:SHAREFLY-WEB-STORAGE');
setTimeout(() => { setTimeout(() => {
window.location.reload(); window.location.reload();
......
...@@ -17,6 +17,7 @@ import getLocationByIP from '@/utils/getLocationByIP'; ...@@ -17,6 +17,7 @@ import getLocationByIP from '@/utils/getLocationByIP';
const HeaderView: React.FC<{ const HeaderView: React.FC<{
placeholder: boolean; placeholder: boolean;
}> = ({ placeholder }) => { }> = ({ placeholder }) => {
const token = Cookies.get('SHAREFLY-WEB-TOKEN');
// 当前的路由数据 // 当前的路由数据
const router = useRouter(); const router = useRouter();
// store // store
...@@ -41,7 +42,7 @@ const HeaderView: React.FC<{ ...@@ -41,7 +42,7 @@ const HeaderView: React.FC<{
}; };
// 获取用户信息 // 获取用户信息
const getAccountInfo = async () => { const getAccountInfo = async () => {
if (!system?.token) return; if (!system?.token || !token) return;
const res = await CommonAPI.getAccountInfo(); const res = await CommonAPI.getAccountInfo();
if (res && res.code === '200') { if (res && res.code === '200') {
dispatch(setUserInfo(res.result)); dispatch(setUserInfo(res.result));
...@@ -58,7 +59,7 @@ const HeaderView: React.FC<{ ...@@ -58,7 +59,7 @@ const HeaderView: React.FC<{
}, []); }, []);
// 当前是否登录 // 当前是否登录
useEffect(() => { useEffect(() => {
if (!system?.token) return; if (!system?.token || !token) return;
getAccountInfo().then(); getAccountInfo().then();
}, [system?.token]); }, [system?.token]);
// 右上角按钮 // 右上角按钮
......
...@@ -162,7 +162,7 @@ const LoginModalView = ({ ...@@ -162,7 +162,7 @@ const LoginModalView = ({
// 设置token // 设置token
dispatch(setSystem({ token: res.result.token })); dispatch(setSystem({ token: res.result.token }));
// 设置token // 设置token
Cookies.set('SHAREFLY-TOKEN', res.result.token); Cookies.set('SHAREFLY-WEB-TOKEN', res.result.token);
message.success('登录成功'); message.success('登录成功');
} }
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论