Browse Source

feat(gui-v2): skip auth validation if shared base route

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3123/head
Pranav C 2 years ago
parent
commit
3957ecebf0
  1. 3
      packages/nc-gui-v2/composables/useApi/interceptors.ts
  2. 4
      packages/nc-gui-v2/composables/useProject.ts
  3. 4
      packages/nc-gui-v2/composables/useTabs.ts
  4. 3
      packages/nc-gui-v2/middleware/auth.global.ts

3
packages/nc-gui-v2/composables/useApi/interceptors.ts

@ -18,7 +18,8 @@ export function addAxiosInterceptors(api: Api<any>) {
}
if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles')) {
if (route && route.params && route.params.projectType === 'base') config.headers['xc-shared-base-id'] = route.params.projectId
if (route && route.params && route.params.projectType === 'base')
config.headers['xc-shared-base-id'] = route.params.projectId
}
return config

4
packages/nc-gui-v2/composables/useProject.ts

@ -32,7 +32,7 @@ export function useProject(projectId?: MaybeRef<string>) {
}
async function loadProject() {
if(unref(projectId)){
if (unref(projectId)) {
_projectId = unref(projectId)!
} else if (projectType === 'base') {
const baseData = await $api.public.sharedBaseGet(route.params.projectId as string)
@ -44,7 +44,7 @@ export function useProject(projectId?: MaybeRef<string>) {
}
watchEffect(async () => {
if (project?.value ) {
if (project?.value) {
await loadProjectRoles()
await loadTables()
}

4
packages/nc-gui-v2/composables/useTabs.ts

@ -1,8 +1,6 @@
import type { WritableComputedRef } from '@vue/reactivity'
import { navigateTo, useProject, useRoute, useState } from '#imports'
import type { RouterConfig } from '@nuxt/schema'
import { navigateTo, useProject, useRoute, useState } from '#imports'
export enum TabType {
TABLE = 'table',

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

@ -23,6 +23,9 @@ import { useGlobal } from '#imports'
export default defineNuxtRouteMiddleware((to, from) => {
const state = useGlobal()
/** if shred base allow without validating token */
if (to.params?.projectType === 'base') return
/** if auth is required or unspecified (same as required) and user is not signed in, redirect to signin page */
if ((to.meta.requiresAuth || typeof to.meta.requiresAuth === 'undefined') && !state.signedIn.value) {
return navigateTo('/signin')

Loading…
Cancel
Save