P粉6589549142023-08-26 11:07:29
根據@Estus Flask的評論,我使用了自定義存儲,並通過直接調用localStorage來管理“記住我”選項,並在localStorage中設置了一個標誌。
plugins: [ createPersistedState({ paths: ["authentication.userAuthenticationInfo"], storage: { getItem(key) { if (localStorage.getItem("rememberMe") == 1) { return localStorage.getItem(key); } else { return Cookies.get(key); //return sessionStorage.getItem(key); } }, setItem(key, value) { if (localStorage.getItem("rememberMe") == 1) { localStorage.setItem(key, value); } else { Cookies.set(key, value); //sessionStorage.setItem(key, value); } }, removeItem(key) { if (localStorage.getItem("rememberMe") == 1) { localStorage.removeItem(key); } else { Cookies.remove(key); //sessionStorage.removeItem(key); } }, }, }), ],
並且我在每次登出或401回應時清除localStorage。