From 2238fc6783a750930689cab70991e312250010bc Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 13 May 2025 09:03:12 +0000 Subject: [PATCH] feat: show no access message if license key limited with 1 workspace --- packages/nc-gui/components/auth/NoAccess.vue | 32 ++++++++++++++++++++ packages/nc-gui/composables/useSsoError.ts | 24 +++++++++++++++ packages/nc-gui/lang/en.json | 5 ++- packages/nc-gui/middleware/03.auth.global.ts | 12 ++++++++ packages/nocodb-sdk/src/lib/globals.ts | 1 + packages/nocodb/src/helpers/catchError.ts | 12 ++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 packages/nc-gui/components/auth/NoAccess.vue create mode 100644 packages/nc-gui/composables/useSsoError.ts diff --git a/packages/nc-gui/components/auth/NoAccess.vue b/packages/nc-gui/components/auth/NoAccess.vue new file mode 100644 index 000000000000..56a9d66e8198 --- /dev/null +++ b/packages/nc-gui/components/auth/NoAccess.vue @@ -0,0 +1,32 @@ + + + diff --git a/packages/nc-gui/composables/useSsoError.ts b/packages/nc-gui/composables/useSsoError.ts new file mode 100644 index 000000000000..751870272850 --- /dev/null +++ b/packages/nc-gui/composables/useSsoError.ts @@ -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) + + const setError = (error: SsoError | null) => { + ssoError.value = error + } + + const clearError = () => { + ssoError.value = null + } + + return { + ssoError, + setError, + clearError, + } +} diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json index b192df05dae8..6ec62a1948f6 100644 --- a/packages/nc-gui/lang/en.json +++ b/packages/nc-gui/lang/en.json @@ -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" } } diff --git a/packages/nc-gui/middleware/03.auth.global.ts b/packages/nc-gui/middleware/03.auth.global.ts index 4a41a06ef9e4..be2d713457da 100644 --- a/packages/nc-gui/middleware/03.auth.global.ts +++ b/packages/nc-gui/middleware/03.auth.global.ts @@ -1,4 +1,5 @@ import type { Api } from 'nocodb-sdk' +import { NcErrorType } from 'nocodb-sdk' import type { Actions } from '~/composables/useGlobal/types' /** @@ -167,6 +168,8 @@ async function tryGoogleAuth(api: Api, 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, signIn: Actions['signIn']) { + const { setError } = useSsoError() + if (window.location.search && /\bshort-token=/.test(window.location.search)) { let extraProps: any = {} try { @@ -188,6 +191,15 @@ async function tryShortTokenAuth(api: Api, 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)) } diff --git a/packages/nocodb-sdk/src/lib/globals.ts b/packages/nocodb-sdk/src/lib/globals.ts index 4ce83b7755c1..2c5ccce37fe6 100644 --- a/packages/nocodb-sdk/src/lib/globals.ts +++ b/packages/nocodb-sdk/src/lib/globals.ts @@ -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 = { diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 51e67b8f427e..1edb9e8cf9c0 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -585,6 +585,7 @@ const errorHelpers: { [key in NcErrorType]: { message: string | ((...params: string[]) => string); code: number; + error_code?: NcErrorType; }; } = { [NcErrorType.UNKNOWN_ERROR]: { @@ -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, @@ -1298,4 +1304,10 @@ export class NcError { ...args, }); } + + static maxWorkspaceLimitReached(args?: NcErrorArgs): never { + throw new NcBaseErrorv2(NcErrorType.MAX_WORKSPACE_LIMIT_REACHED, { + ...args, + }); + } }