|
@@ -1,11 +1,11 @@
|
|
|
import UserApi, { LoginResult, UserInfo } from "@/api/auth/UserApi";
|
|
import UserApi, { LoginResult, UserInfo } from "@/api/auth/UserApi";
|
|
|
-import { SettingsUtils } from "@imengyu/imengyu-utils";
|
|
|
|
|
|
|
+import { HtmlUtils, SettingsUtils } from "@imengyu/imengyu-utils";
|
|
|
import { defineStore } from "pinia"
|
|
import { defineStore } from "pinia"
|
|
|
|
|
+import { useRoute, type RouteLocationNormalizedLoadedGeneric } from "vue-router";
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'authInfo';
|
|
const STORAGE_KEY = 'authInfo';
|
|
|
const canRefresh = false;
|
|
const canRefresh = false;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
export const useAuthStore = defineStore('auth', {
|
|
export const useAuthStore = defineStore('auth', {
|
|
|
state: () => ({
|
|
state: () => ({
|
|
|
token: '',
|
|
token: '',
|
|
@@ -13,11 +13,19 @@ export const useAuthStore = defineStore('auth', {
|
|
|
userId: 0,
|
|
userId: 0,
|
|
|
userInfo: null as null|UserInfo,
|
|
userInfo: null as null|UserInfo,
|
|
|
loginType: 0,
|
|
loginType: 0,
|
|
|
|
|
+ loginFromEmbed: false,
|
|
|
}),
|
|
}),
|
|
|
actions: {
|
|
actions: {
|
|
|
- async loadLoginState() {
|
|
|
|
|
|
|
+ async loadLoginState(route: RouteLocationNormalizedLoadedGeneric) {
|
|
|
try {
|
|
try {
|
|
|
- const res = localStorage.getItem(STORAGE_KEY);
|
|
|
|
|
|
|
+ const query = route.query.internalAuth as string|undefined;
|
|
|
|
|
+ let res = localStorage.getItem(STORAGE_KEY);
|
|
|
|
|
+ this.loginFromEmbed = false;
|
|
|
|
|
+ if (!res && query) {
|
|
|
|
|
+ res = decodeURIComponent(query);
|
|
|
|
|
+ this.loginFromEmbed = true;
|
|
|
|
|
+ localStorage.setItem(STORAGE_KEY, res);
|
|
|
|
|
+ }
|
|
|
if (!res)
|
|
if (!res)
|
|
|
throw 'no storage';
|
|
throw 'no storage';
|
|
|
const authInfo = JSON.parse(res);
|
|
const authInfo = JSON.parse(res);
|
|
@@ -28,10 +36,10 @@ export const useAuthStore = defineStore('auth', {
|
|
|
this.loginType = authInfo.loginType;
|
|
this.loginType = authInfo.loginType;
|
|
|
|
|
|
|
|
// 检查token是否过期,如果快要过期,则刷新token
|
|
// 检查token是否过期,如果快要过期,则刷新token
|
|
|
- if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
|
|
|
|
|
|
|
+ /*if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
|
|
|
const refreshResult = await UserApi.refresh();
|
|
const refreshResult = await UserApi.refresh();
|
|
|
this.loginResultHandle(refreshResult, this.loginType);
|
|
this.loginResultHandle(refreshResult, this.loginType);
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
this.token = '';
|
|
this.token = '';
|
|
|
this.userId = 0;
|
|
this.userId = 0;
|