Browse Source

fix: clear store values only after redirecting to SignIn page (#9412)

pull/7999/merge
Pranav C 3 months ago committed by GitHub
parent
commit
382156fab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      packages/nc-gui/components/account/ResetPassword.vue
  2. 1
      packages/nc-gui/components/account/Setup.vue
  3. 10
      packages/nc-gui/components/dashboard/Sidebar/UserInfo.vue
  4. 5
      packages/nc-gui/components/general/MiniSidebar.vue
  5. 6
      packages/nc-gui/composables/useApi/interceptors.ts
  6. 9
      packages/nc-gui/composables/useGlobal/actions.ts
  7. 10
      packages/nc-gui/composables/useGlobal/types.ts
  8. 5
      packages/nc-gui/layouts/base.vue
  9. 5
      packages/nc-gui/layouts/new.vue
  10. 3
      packages/nc-gui/middleware/02.auth.global.ts
  11. 5
      packages/nc-gui/pages/account/index.vue

6
packages/nc-gui/components/account/ResetPassword.vue

@ -46,9 +46,9 @@ const passwordChange = async () => {
message.success(t('msg.success.passwordChanged'))
await signOut()
await navigateTo('/signin')
await signOut({
redirectToSignin: true,
})
}
const resetError = () => {

1
packages/nc-gui/components/account/Setup.vue

@ -73,6 +73,7 @@ onMounted(async () => {
<div class="flex flex-col gap-6 w-150">
<div
v-for="config of configs"
:key="config.key"
class="flex flex-col border-1 rounded-2xl border-gray-200 p-6 gap-2 hover:(shadow bg-gray-10)"
:class="{
'cursor-pointer': config.itemClick,

10
packages/nc-gui/components/dashboard/Sidebar/UserInfo.vue

@ -22,12 +22,10 @@ const logout = async () => {
try {
const isSsoUser = !!(user?.value as any)?.sso_client_id
await signOut(false)
// No need as all stores are cleared on signout
// await clearWorkspaces()
await navigateTo(isSsoUser ? '/sso' : '/signin')
await signOut({
redirectToSignin: true,
signinUrl: isSsoUser ? '/sso' : '/signin',
})
} catch (e) {
console.error(e)
} finally {

5
packages/nc-gui/components/general/MiniSidebar.vue

@ -10,8 +10,9 @@ const route = useRoute()
const email = computed(() => user.value?.email ?? '---')
const logout = async () => {
await signOut(false)
await navigateTo('/signin')
await signOut({
redirectToSignin: true,
})
}
</script>

6
packages/nc-gui/composables/useApi/interceptors.ts

@ -124,9 +124,9 @@ export function addAxiosInterceptors(api: Api<any>) {
})
})
.catch(async (refreshTokenError) => {
await state.signOut()
if (!route.value.meta.public) navigateTo('/signIn')
await state.signOut({
redirectToSignin: !route.value.meta.public,
})
// reject the refresh token promise and reset
refreshTokenPromiseRej(refreshTokenError)

9
packages/nc-gui/composables/useGlobal/actions.ts

@ -1,5 +1,5 @@
import { getActivePinia } from 'pinia'
import type { Actions, AppInfo, State } from './types'
import type { Actions, AppInfo, SignOutParams, State } from './types'
import type { NcProjectType } from '#imports'
export function useGlobalActions(state: State): Actions {
@ -8,15 +8,20 @@ export function useGlobalActions(state: State): Actions {
}
/** 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 {
const nuxtApp = useNuxtApp()
await nuxtApp.$api.auth.signout()
} catch {
// ignore error
} finally {
state.token.value = null
state.user.value = null
if (redirectToSignin) {
await navigateTo(signinUrl)
}
// clear all stores data on logout
const pn = getActivePinia()
if (pn) {

10
packages/nc-gui/composables/useGlobal/types.ts

@ -80,9 +80,15 @@ export interface Getters {
isLoading: WritableComputedRef<boolean>
}
export interface SignOutParams {
redirectToSignin?: boolean
signinUrl?: string
skipRedirect?: boolean
}
export interface Actions {
signOut: (skipRedirect?: boolean) => void
signIn: (token: string, keepProps?: boolean) => void
signOut: (signOutParams?: SignOutParams) => Promise<void>
signIn: (token: string, keepProps?: boolean) => Promise<void>
refreshToken: () => void
loadAppInfo: () => void
setIsMobileMode: (isMobileMode: boolean) => void

5
packages/nc-gui/layouts/base.vue

@ -12,8 +12,9 @@ const hasSider = ref(false)
const sidebar = ref<HTMLDivElement>()
const logout = async () => {
await signOut(false)
await navigateTo('/signin')
await signOut({
redirectToSignin: true,
})
}
const { hooks } = useNuxtApp()

5
packages/nc-gui/layouts/new.vue

@ -33,8 +33,9 @@ watch(hasSidebar, (val) => {
})
const logout = async () => {
await signOut(false)
await navigateTo('/signin')
await signOut({
redirectToSignin: true,
})
await clearWorkspaces()
}
</script>

3
packages/nc-gui/middleware/02.auth.global.ts

@ -88,8 +88,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
}
} else if (to.meta.requiresAuth === false && state.signedIn.value) {
if (to.query?.logout) {
await state.signOut(true)
return navigateTo('/signin')
await state.signOut({ redirectToSignin: true })
}
/**

5
packages/nc-gui/pages/account/index.vue

@ -20,8 +20,9 @@ const selectedKeys = computed(() => [
const openKeys = ref([/^\/account\/users/.test($route.fullPath) && 'users'])
const logout = async () => {
await signOut(false)
navigateTo('/signin')
await signOut({
redirectToSignin: true,
})
}
const isSetupPageAllowed = computed(() => isUIAllowed('superAdminSetup') && !isEeUI)

Loading…
Cancel
Save