diff --git a/src/composables/useState.js b/src/composables/useState.js index e0b742a73..e671d41bd 100644 --- a/src/composables/useState.js +++ b/src/composables/useState.js @@ -13,6 +13,7 @@ const user = ref({ }); const roles = ref([]); +const tokenConfig = ref({}); const drawer = ref(true); const headerMounted = ref(false); @@ -52,6 +53,15 @@ export function useState() { function setRoles(data) { roles.value = data; } + function getTokenConfig() { + return computed(() => { + return tokenConfig.value; + }); + } + + function setTokenConfig(data) { + tokenConfig.value = data; + } function set(name, data) { state.value[name] = ref(data); @@ -70,6 +80,8 @@ export function useState() { setUser, getRoles, setRoles, + getTokenConfig, + setTokenConfig, set, get, unset, diff --git a/src/composables/useTokenConfig.js b/src/composables/useTokenConfig.js new file mode 100644 index 000000000..3119a6aa6 --- /dev/null +++ b/src/composables/useTokenConfig.js @@ -0,0 +1,26 @@ +import axios from 'axios'; +import { useState } from './useState'; +import useNotify from './useNotify'; + +export function useTokenConfig() { + const state = useState(); + const { notify } = useNotify(); + + async function fetch() { + try { + const tokenConfig = await axios.get('AccessTokenConfigs/findOne', { + filter: { fields: ['renewInterval', 'renewPeriod'] }, + }); + if (!tokenConfig) return; + state.setTokenConfig(tokenConfig); + return tokenConfig; + } catch (error) { + notify('errors.tokenConfig', 'negative'); + console.error('Error fetching token config:', error); + } + } + + return { + fetch, + }; +} diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index db34b393c..bcdc6dca1 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -96,6 +96,7 @@ errors: statusBadGateway: It seems that the server has fall down statusGatewayTimeout: Could not contact the server userConfig: Error fetching user config + tokenConfig: Error fetching token config writeRequest: The requested operation could not be completed login: title: Login diff --git a/src/i18n/locale/es.yml b/src/i18n/locale/es.yml index cb5876dd3..73eb70e60 100644 --- a/src/i18n/locale/es.yml +++ b/src/i18n/locale/es.yml @@ -96,6 +96,7 @@ errors: statusBadGateway: Parece ser que el servidor ha caído statusGatewayTimeout: No se ha podido contactar con el servidor userConfig: Error al obtener configuración de usuario + tokenConfig: Error al obtener configuración de token writeRequest: No se pudo completar la operación solicitada login: title: Inicio de sesión