fix: 🐛 缓存命名更改全局调整
This commit is contained in:
@@ -105,8 +105,8 @@ function createOnlineCountHook() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用 Auth.getAccessToken() 获取令牌,确保获取到最新的
|
||||
const accessToken = Auth.getAccessToken();
|
||||
// 使用 AuthStorage.getAccessToken() 获取令牌,确保获取到最新的
|
||||
const accessToken = AuthStorage.getAccessToken();
|
||||
if (!accessToken) {
|
||||
console.log("[useOnlineCount] 没有检测到有效令牌,不尝试WebSocket连接");
|
||||
return;
|
||||
@@ -129,7 +129,7 @@ function createOnlineCountHook() {
|
||||
closeWebSocket();
|
||||
setTimeout(() => {
|
||||
// 再次检查令牌有效性
|
||||
if (Auth.getAccessToken()) {
|
||||
if (AuthStorage.getAccessToken()) {
|
||||
initWebSocket();
|
||||
} else {
|
||||
console.log("[useOnlineCount] 令牌无效,放弃重连");
|
||||
|
||||
@@ -70,7 +70,7 @@ export function useStomp(options: UseStompOptions = {}) {
|
||||
}
|
||||
|
||||
// 每次连接前重新获取最新令牌,不依赖之前的token值
|
||||
const currentToken = Auth.getAccessToken();
|
||||
const currentToken = AuthStorage.getAccessToken();
|
||||
|
||||
// 检查令牌是否为空,如果为空则不进行连接
|
||||
if (!currentToken) {
|
||||
|
||||
@@ -43,8 +43,8 @@ export function setupWebSocket() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否已登录
|
||||
if (!Auth.isLoggedIn()) {
|
||||
// 检查是否已登录(基于是否存在访问令牌)
|
||||
if (!AuthStorage.getAccessToken()) {
|
||||
console.warn(
|
||||
"[WebSocketPlugin] 未找到访问令牌,WebSocket初始化已跳过。用户登录后将自动重新连接。"
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Storage } from "./storage";
|
||||
import { AUTH_KEYS } from "@/constants";
|
||||
|
||||
// 更语义化的命名:仅负责本地凭证与偏好的读写
|
||||
// 负责本地凭证与偏好的读写
|
||||
export const AuthStorage = {
|
||||
getAccessToken(): string {
|
||||
const isRememberMe = Storage.get<boolean>(AUTH_KEYS.REMEMBER_ME, false);
|
||||
|
||||
Reference in New Issue
Block a user