|
|
@@ -18,20 +18,25 @@ export const useAuthStore = defineStore('auth', {
|
|
|
actions: {
|
|
|
async loadLoginState() {
|
|
|
try {
|
|
|
+ let fromMp = false;
|
|
|
let res = localStorage.getItem(STORAGE_KEY);
|
|
|
- if (!res) {
|
|
|
- const directAuthInfo = HtmlUtils.getQueryVariable('directAuthInfo');
|
|
|
- if (directAuthInfo)
|
|
|
- res = directAuthInfo;
|
|
|
- else
|
|
|
- throw 'no storage';
|
|
|
+ const directAuthInfo = HtmlUtils.getQueryVariable('directAuthInfo');
|
|
|
+ if (directAuthInfo) {
|
|
|
+ res = decodeURIComponent(directAuthInfo);
|
|
|
+ fromMp = true;
|
|
|
}
|
|
|
+
|
|
|
+ if (!res)
|
|
|
+ throw 'no storage';
|
|
|
+
|
|
|
const authInfo = JSON.parse(res);
|
|
|
this.token = authInfo.token;
|
|
|
this.userId = authInfo.userId;
|
|
|
this.expireAt = authInfo.expireAt;
|
|
|
this.userInfo = authInfo.userInfo;
|
|
|
this.loginType = authInfo.loginType;
|
|
|
+ if (fromMp)
|
|
|
+ this.saveLogData();
|
|
|
|
|
|
// 检查token是否过期,如果快要过期,则刷新token
|
|
|
if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
|
|
|
@@ -68,25 +73,27 @@ export const useAuthStore = defineStore('auth', {
|
|
|
this.userInfo = loginResult.userInfo;
|
|
|
this.loginType = loginType;
|
|
|
this.expireAt = (loginResult.expiresIn || 0) + Date.now();
|
|
|
+ this.saveLogData();
|
|
|
+ },
|
|
|
+ async logout() {
|
|
|
+ this.token = '';
|
|
|
+ this.userId = 0;
|
|
|
+ this.userInfo = null;
|
|
|
|
|
|
+ SettingsUtils.setSettings('inheritorShowInMessageLastTime', 0);
|
|
|
+ localStorage.removeItem(STORAGE_KEY);
|
|
|
+ },
|
|
|
+ saveLogData() {
|
|
|
localStorage.setItem(STORAGE_KEY,
|
|
|
JSON.stringify({
|
|
|
token: this.token,
|
|
|
userId: this.userId ,
|
|
|
expireAt: this.expireAt,
|
|
|
userInfo: this.userInfo,
|
|
|
- loginType,
|
|
|
+ loginType: this.loginType,
|
|
|
})
|
|
|
);
|
|
|
},
|
|
|
- async logout() {
|
|
|
- this.token = '';
|
|
|
- this.userId = 0;
|
|
|
- this.userInfo = null;
|
|
|
-
|
|
|
- SettingsUtils.setSettings('inheritorShowInMessageLastTime', 0);
|
|
|
- localStorage.removeItem(STORAGE_KEY);
|
|
|
- }
|
|
|
},
|
|
|
getters: {
|
|
|
isAdmin(state) {
|