fix: logout
This commit is contained in:
@@ -56,7 +56,7 @@ const authDataSlice = createSlice({
|
||||
state.guest = create_by == "guest";
|
||||
state.token = token;
|
||||
state.refreshToken = refresh_token;
|
||||
// 当前时间往后推expire时长
|
||||
// 当前时间往后推 expire 时长
|
||||
const expireTime = +new Date() + Number(expired_in) * 1000;
|
||||
state.expireTime = expireTime;
|
||||
// set local data
|
||||
@@ -89,6 +89,9 @@ const authDataSlice = createSlice({
|
||||
localStorage.removeItem(KEY_REFRESH_TOKEN);
|
||||
localStorage.removeItem(KEY_UID);
|
||||
localStorage.removeItem(KEY_PWA_INSTALLED);
|
||||
// 全局变量
|
||||
window.USERS_VERSION = 0;
|
||||
window.AFTER_MID = 0;
|
||||
return emptyState;
|
||||
},
|
||||
updateInitialized(state, action: PayloadAction<boolean>) {
|
||||
|
||||
@@ -15,19 +15,19 @@ export default function useLogout() {
|
||||
const dispatch = useDispatch();
|
||||
const [logout, { isLoading, isSuccess }] = useLazyLogoutQuery();
|
||||
const clearLocalData = (auth?: boolean) => {
|
||||
let clearAuth = typeof auth === "undefined" ? false : auth;
|
||||
const clearAuth = typeof auth === "undefined" ? false : auth;
|
||||
dispatch(resetChannels());
|
||||
dispatch(resetUsers());
|
||||
dispatch(resetFootprint());
|
||||
// 同时也清除本地登录数据
|
||||
if (clearAuth) {
|
||||
dispatch(resetAuthData());
|
||||
}
|
||||
dispatch(resetChannelMsg());
|
||||
dispatch(resetUserMsg());
|
||||
dispatch(resetMessage());
|
||||
dispatch(resetReactionMessage());
|
||||
dispatch(resetFileMessage());
|
||||
// 同时也清除本地登录数据
|
||||
if (clearAuth) {
|
||||
dispatch(resetAuthData());
|
||||
}
|
||||
};
|
||||
|
||||
return { clearLocalData, logout, exited: isSuccess, exiting: isLoading };
|
||||
|
||||
@@ -130,9 +130,9 @@ export default function useStreaming() {
|
||||
params.after_mid = `${window.AFTER_MID}`;
|
||||
}
|
||||
// 如果 usersVersion 不存在或为 0,则不传该参数
|
||||
// if (window.USERS_VERSION) {
|
||||
params.users_version = window.USERS_VERSION ? `${window.USERS_VERSION}` : "1";
|
||||
// }
|
||||
if (window.USERS_VERSION) {
|
||||
params.users_version = `${window.USERS_VERSION}`;
|
||||
}
|
||||
// 开始初始化推送
|
||||
dispatch(updateSSEStatus("connecting"));
|
||||
SSE = new EventSource(`${BASE_URL}/user/events?${getQueryString(params)}`);
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
// import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { shallowEqual, useDispatch } from "react-redux";
|
||||
import { shallowEqual } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { BASE_ORIGIN } from "@/app/config";
|
||||
import { resetAuthData } from "@/app/slices/auth.data";
|
||||
// import { resetAuthData } from "@/app/slices/auth.data";
|
||||
import { useAppSelector } from "@/app/store";
|
||||
import QRCode from "@/components/QRCode";
|
||||
import Button from "@/components/styled/Button";
|
||||
import useLogout from "@/hooks/useLogout";
|
||||
// import useLogout from "@/hooks/useLogout";
|
||||
|
||||
// type Props = {};
|
||||
|
||||
const GuestBlankPlaceholder = () => {
|
||||
const { t } = useTranslation("auth");
|
||||
const dispatch = useDispatch();
|
||||
const { clearLocalData } = useLogout();
|
||||
// const dispatch = useDispatch();
|
||||
// const { clearLocalData } = useLogout();
|
||||
const navigateTo = useNavigate();
|
||||
const serverName = useAppSelector((store) => store.server.name, shallowEqual);
|
||||
const handleSignIn = () => {
|
||||
dispatch(resetAuthData());
|
||||
clearLocalData();
|
||||
// dispatch(resetAuthData());
|
||||
// clearLocalData();
|
||||
navigateTo("/login");
|
||||
};
|
||||
const qrUrl = BASE_ORIGIN;
|
||||
|
||||
Reference in New Issue
Block a user