Browse Source

Merge pull request #3471 from nocodb/fix/gui-v2-permission-middleware

fix(gui-v2): show error message when accessing projects with insuffic…
pull/3475/head
Raju Udava 2 years ago committed by GitHub
parent
commit
a4700f6766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/nc-gui-v2/middleware/auth.global.ts

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

@ -36,6 +36,8 @@ import { useApi, useGlobal } from '#imports'
export default defineNuxtRouteMiddleware(async (to, from) => { export default defineNuxtRouteMiddleware(async (to, from) => {
const state = useGlobal() const state = useGlobal()
const { api } = useApi()
/** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */ /** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */
if (!state.signedIn && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth() if (!state.signedIn && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth()
@ -65,6 +67,15 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
} else { } else {
return navigateTo(from.path) return navigateTo(from.path)
} }
} else {
/** if users are accessing the projects without having enough permissions, redirect to My Projects page */
if (to.params.projectId) {
const user = await api.auth.me({ project_id: to?.params?.projectId as string })
if (user?.roles?.user) {
message.error("You don't have enough permission to access the project.")
return navigateTo('/')
}
}
} }
}) })

Loading…
Cancel
Save