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')) message.success(t('msg.success.passwordChanged'))
await signOut() await signOut({
redirectToSignin: true,
await navigateTo('/signin') })
} }
const resetError = () => { 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 class="flex flex-col gap-6 w-150">
<div <div
v-for="config of configs" 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="flex flex-col border-1 rounded-2xl border-gray-200 p-6 gap-2 hover:(shadow bg-gray-10)"
:class="{ :class="{
'cursor-pointer': config.itemClick, 'cursor-pointer': config.itemClick,

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

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

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

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

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

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

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

@ -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) {

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

@ -80,9 +80,15 @@ export interface Getters {
isLoading: WritableComputedRef<boolean> isLoading: WritableComputedRef<boolean>
} }
export interface SignOutParams {
redirectToSignin?: boolean
signinUrl?: string
skipRedirect?: boolean
}
export interface Actions { export interface Actions {
signOut: (skipRedirect?: boolean) => void signOut: (signOutParams?: SignOutParams) => Promise<void>
signIn: (token: string, keepProps?: boolean) => void signIn: (token: string, keepProps?: boolean) => Promise<void>
refreshToken: () => void refreshToken: () => void
loadAppInfo: () => void loadAppInfo: () => void
setIsMobileMode: (isMobileMode: boolean) => 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 sidebar = ref<HTMLDivElement>()
const logout = async () => { const logout = async () => {
await signOut(false) await signOut({
await navigateTo('/signin') redirectToSignin: true,
})
} }
const { hooks } = useNuxtApp() const { hooks } = useNuxtApp()

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

@ -33,8 +33,9 @@ watch(hasSidebar, (val) => {
}) })
const logout = async () => { const logout = async () => {
await signOut(false) await signOut({
await navigateTo('/signin') redirectToSignin: true,
})
await clearWorkspaces() await clearWorkspaces()
} }
</script> </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) { } else if (to.meta.requiresAuth === false && state.signedIn.value) {
if (to.query?.logout) { if (to.query?.logout) {
await state.signOut(true) await state.signOut({ redirectToSignin: true })
return navigateTo('/signin')
} }
/** /**

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 openKeys = ref([/^\/account\/users/.test($route.fullPath) && 'users'])
const logout = async () => { const logout = async () => {
await signOut(false) await signOut({
navigateTo('/signin') redirectToSignin: true,
})
} }
const isSetupPageAllowed = computed(() => isUIAllowed('superAdminSetup') && !isEeUI) const isSetupPageAllowed = computed(() => isUIAllowed('superAdminSetup') && !isEeUI)

Loading…
Cancel
Save