8000 feat: show no access message if license key limited with 1 workspace by dstala · Pull Request #11366 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: show no access message if license key limited with 1 workspace #11366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/nc-gui/components/auth/NoAccess.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useSsoError } from '~/composables/useSsoError'

defineProps<{
message?: string
}>()
const { t } = useI18n()
const { clearError } = useSsoError()

const handleRetry = () => {
clearError()
}
</script>

<template>
<div class="flex flex-col items-center justify-center min-h-screen bg-gray-50">
<div class="w-full max-w-md p-8 space-y-8 bg-white rounded-lg shadow">
<div class="text-center">
<h1 class="text-2xl font-bold text-gray-900">
{{ t('msg.noAccess') }}
</h1>
<p class="mt-2 text-sm text-gray-600">
{{ message || t('msg.noAccessDescription') }}
</p>
<NcButton class="mt-4" type="primary" size="medium" @click="handleRetry">
{{ t('msg.tryAgain') }}
</NcButton>
</div>
</div>
</div>
</template>
24 changes: 24 additions & 0 deletions packages/nc-gui/composables/useSsoError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { NcErrorType } from 'nocodb-sdk'

export interface SsoError {
type: NcErrorType
message: string
}

export const useSsoError = () => {
const ssoError = useState<SsoError | null>('ssoError', () => null)

const setError = (error: SsoError | null) => {
ssoError.value = error
}

const clearError = () => {
ssoError.value = null
}

return {
ssoError,
setError,
clearError,
}
}
5 changes: 4 additions & 1 deletion packages/nc-gui/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,9 @@
"createNewTable": "Start from scratch.",
"importData": "From files & external sources.",
"connectExternalData": "In realtime to external databases."
}
},
"noAccess": "No Access",
"noAccessDescription": "You don't have access to any workspace. Please contact your administrator to request access.",
"tryAgain": "Try Again"
}
}
12 changes: 12 additions & 0 deletions packages/nc-gui/middleware/03.auth.global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Api } from 'nocodb-sdk'
import { NcErrorType } from 'nocodb-sdk'
import type { Actions } from '~/composables/useGlobal/types'

/**
Expand Down Expand Up @@ -167,6 +168,8 @@ async function tryGoogleAuth(api: Api<any>, signIn: Actions['signIn']) {
* If short-token present, try using it to generate long-living token before navigating to the next page
*/
async function tryShortTokenAuth(api: Api<any>, signIn: Actions['signIn']) {
const { setError } = useSsoError()

if (window.location.search && /\bshort-token=/.test(window.location.search)) {
let extraProps: any = {}
try {
Expand All @@ -188,6 +191,15 @@ async function tryShortTokenAuth(api: Api<any>, signIn: Actions['signIn']) {

signIn(token)
} catch (e: any) {
if (e?.response?.data?.error === NcErrorType.MAX_WORKSPACE_LIMIT_REACHED) {
// Store error information in global state
setError({
type: NcErrorType.MAX_WORKSPACE_LIMIT_REACHED,
message: e?.response?.data?.message || 'Maximum workspace limit reached',
})
// navigate to sso page and display the error details
return await navigateTo('/sso')
}
message.error(await extractSdkResponseErrorMsg(e))
}

Expand Down
1 change: 1 addition & 0 deletions packages/nocodb-sdk/src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export enum NcErrorType {
SSO_LOGIN_REQUIRED = 'SSO_LOGIN_REQUIRED',
MAX_INSERT_LIMIT_EXCEEDED = 'MAX_INSERT_LIMIT_EXCEEDED',
INVALID_VALUE_FOR_FIELD = 'INVALID_VALUE_FOR_FIELD',
MAX_WORKSPACE_LIMIT_REACHED = 'MAX_WORKSPACE_LIMIT_REACHED',
}

export const NcErrorTypeMap = {
Expand Down
12 changes: 12 additions & 0 deletions packages/nocodb/src/helpers/catchError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ const errorHelpers: {
[key in NcErrorType]: {
message: string | ((...params: string[]) => string);
code: number;
error_code?: NcErrorType;
};
} = {
[NcErrorType.UNKNOWN_ERROR]: {
Expand Down Expand Up @@ -797,6 +798,11 @@ const errorHelpers: {
message: (limit: string) => `Maximum ${limit} records during insert`,
code: 422,
},
[NcErrorType.MAX_WORKSPACE_LIMIT_REACHED]: {
message: () =>
`The maximum workspace limit has been reached. Please contact your administrator to request access to a workspace.`,
code: 403,
},
[NcErrorType.INVALID_VALUE_FOR_FIELD]: {
message: (message: string) => message,
code: 422,
Expand Down Expand Up @@ -1298,4 +1304,10 @@ export class NcError {
...args,
});
}

static maxWorkspaceLimitReached(args?: NcErrorArgs): never {
throw new NcBaseErrorv2(NcErrorType.MAX_WORKSPACE_LIMIT_REACHED, {
...args,
});
}
}
Loading
0