diff --git a/packages/nc-gui/composables/useGlobal/actions.ts b/packages/nc-gui/composables/useGlobal/actions.ts index caa8061c77..0da1f4e2d9 100644 --- a/packages/nc-gui/composables/useGlobal/actions.ts +++ b/packages/nc-gui/composables/useGlobal/actions.ts @@ -1,10 +1,8 @@ import { getActivePinia } from 'pinia' -import { useStorage } from '@vueuse/core' import type { Actions, AppInfo, Getters, State } from './types' import type { NcProjectType } from '#imports' export function useGlobalActions(state: State, getters: Getters): Actions { - const isTokenRefreshInProgress = useStorage(TOKEN_REFRESH_PROGRESS_KEY, false) const isTokenUpdatedTab = useState('isTokenUpdatedTab', () => false) const setIsMobileMode = (isMobileMode: boolean) => { @@ -65,7 +63,7 @@ export function useGlobalActions(state: State, getters: Getters): Actions { } /** manually try to refresh token */ - const refreshToken = async ({ + const _refreshToken = async ({ axiosInstance, skipSignOut = false, }: { @@ -75,16 +73,6 @@ export function useGlobalActions(state: State, getters: Getters): Actions { const nuxtApp = useNuxtApp() const t = nuxtApp.vueApp.i18n.global.t - // if token refresh is already in progress, wait until it is completed or timeout - if (isTokenRefreshInProgress.value) { - await until(isTokenRefreshInProgress).toMatch((v) => !v, { timeout: 10000 }) - - // if token is already refreshed and valid return the token - if (getters.signedIn.value && state.token.value) { - isTokenRefreshInProgress.value = false - return state.token.value - } - } isTokenRefreshInProgress.value = true if (!axiosInstance) { @@ -108,11 +96,13 @@ export function useGlobalActions(state: State, getters: Getters): Actions { message.error(t('msg.error.youHaveBeenSignedOut')) } return null - } finally { - isTokenRefreshInProgress.value = false } } + const refreshToken = useSharedExecutionFn('refreshToken', _refreshToken, { + timeout: 10000, + }) + const loadAppInfo = async () => { try { const nuxtApp = useNuxtApp() diff --git a/packages/nc-gui/composables/useGlobal/types.ts b/packages/nc-gui/composables/useGlobal/types.ts index d82b6a2542..1ad3975705 100644 --- a/packages/nc-gui/composables/useGlobal/types.ts +++ b/packages/nc-gui/composables/useGlobal/types.ts @@ -92,7 +92,7 @@ export interface SignOutParams { export interface Actions { signOut: (signOutParams?: SignOutParams) => Promise signIn: (token: string, keepProps?: boolean) => void - refreshToken: (params: { axiosInstance?: AxiosInstance; skipLogout?: boolean }) => Promise + refreshToken: (params: { axiosInstance?: AxiosInstance; skipLogout?: boolean; cognitoOnly?: boolean }) => Promise loadAppInfo: () => void setIsMobileMode: (isMobileMode: boolean) => void navigateToProject: (params: { workspaceId?: string; baseId?: string; type?: NcProjectType; query?: any }) => void