|
|
@ -1,5 +1,5 @@ |
|
|
|
import { getActivePinia } from 'pinia' |
|
|
|
import { getActivePinia } from 'pinia' |
|
|
|
import type { Actions, AppInfo, State } from './types' |
|
|
|
import type { Actions, AppInfo, SignOutParams, State } from './types' |
|
|
|
import type { NcProjectType } from '#imports' |
|
|
|
import type { NcProjectType } from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
export function useGlobalActions(state: State): Actions { |
|
|
|
export function useGlobalActions(state: State): Actions { |
|
|
@ -8,15 +8,20 @@ export function useGlobalActions(state: State): Actions { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Sign out by deleting the token from localStorage */ |
|
|
|
/** Sign out by deleting the token from localStorage */ |
|
|
|
const signOut: Actions['signOut'] = async (_skipRedirect = false) => { |
|
|
|
const signOut: Actions['signOut'] = async ({ redirectToSignin, signinUrl = '/signin' }: SignOutParams = {}) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const nuxtApp = useNuxtApp() |
|
|
|
const nuxtApp = useNuxtApp() |
|
|
|
await nuxtApp.$api.auth.signout() |
|
|
|
await nuxtApp.$api.auth.signout() |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
|
|
|
|
// ignore error
|
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
state.token.value = null |
|
|
|
state.token.value = null |
|
|
|
state.user.value = null |
|
|
|
state.user.value = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (redirectToSignin) { |
|
|
|
|
|
|
|
await navigateTo(signinUrl) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// clear all stores data on logout
|
|
|
|
// clear all stores data on logout
|
|
|
|
const pn = getActivePinia() |
|
|
|
const pn = getActivePinia() |
|
|
|
if (pn) { |
|
|
|
if (pn) { |
|
|
|