diff --git a/web/src/api/token.ts b/web/src/api/token.ts new file mode 100644 index 00000000..903c213b --- /dev/null +++ b/web/src/api/token.ts @@ -0,0 +1,10 @@ +import request from '@/utils/request/axios' + +export async function fetchAPIToken() { + try { + const response = await request.get('/token_10years') + return response.data + } catch (error) { + throw error + } +} \ No newline at end of file diff --git a/web/src/store/modules/auth/index.ts b/web/src/store/modules/auth/index.ts index 17a6ef0a..aba61eb0 100644 --- a/web/src/store/modules/auth/index.ts +++ b/web/src/store/modules/auth/index.ts @@ -13,6 +13,12 @@ export const useAuthStore = defineStore('auth-store', { expiresIn: getExpiresIn(), }), + getters: { + isValid(): boolean { + return !!(this.token && this.expiresIn && this.expiresIn > Date.now() / 1000) + }, + }, + actions: { getToken() { return this.token @@ -36,6 +42,7 @@ export const useAuthStore = defineStore('auth-store', { this.expiresIn = undefined removeExpiresIn() }, + }, }) diff --git a/web/src/views/admin/index.vue b/web/src/views/admin/index.vue index 7faf0fc2..a7798124 100644 --- a/web/src/views/admin/index.vue +++ b/web/src/views/admin/index.vue @@ -20,13 +20,13 @@ const USER_ROUTE = 'AdminUser' const MODEL_ROUTE = 'AdminModel' const MODELRATELIMIT_ROUTUE = 'ModelRateLimit' -const needPermission = computed(() => !authStore.token) // || (!!authStore.token && authStore.expiresIn < Date.now() / 1000)) +const needPermission = computed(() => !authStore.isValid) const collapsed: Ref = ref(false) const activeKey = ref(currentRoute.name?.toString()) const getMobileClass = computed(() => { - if (isMobile.value) { + if (isMobile.value) { return { zIndex: 50, } @@ -94,40 +94,39 @@ function handleChatHome() { diff --git a/web/src/views/bot/all.vue b/web/src/views/bot/all.vue index 19c4648b..0d8412cf 100644 --- a/web/src/views/bot/all.vue +++ b/web/src/views/bot/all.vue @@ -1,33 +1,30 @@