From 290356c20d87f05b8532663cbfed6f582f527339 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 17 Jul 2023 10:49:44 +0530 Subject: [PATCH] fix: handle tenant not found error --- .../recipe/multitenancy/api/implementation.js | 12 ++++++ lib/build/recipe/multitenancy/index.d.ts | 37 +++++++++++-------- lib/build/recipe/multitenancy/types.d.ts | 37 +++++++++++-------- .../recipe/thirdparty/recipeImplementation.js | 7 ++++ .../recipe/multitenancy/api/implementation.ts | 8 ++++ lib/ts/recipe/multitenancy/index.ts | 33 ++++++++++------- lib/ts/recipe/multitenancy/types.ts | 33 ++++++++++------- .../recipe/thirdparty/recipeImplementation.ts | 8 ++++ 8 files changed, 115 insertions(+), 60 deletions(-) diff --git a/lib/build/recipe/multitenancy/api/implementation.js b/lib/build/recipe/multitenancy/api/implementation.js index f8793cafe..79f06ca3c 100644 --- a/lib/build/recipe/multitenancy/api/implementation.js +++ b/lib/build/recipe/multitenancy/api/implementation.js @@ -30,8 +30,14 @@ var __awaiter = step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; Object.defineProperty(exports, "__esModule", { value: true }); const configUtils_1 = require("../../thirdparty/providers/configUtils"); +const error_1 = __importDefault(require("../error")); function getAPIInterface() { return { loginMethodsGET: function ({ tenantId, clientType, options, userContext }) { @@ -40,6 +46,12 @@ function getAPIInterface() { tenantId, userContext, }); + if (tenantConfigRes.status === "TENANT_NOT_FOUND_ERROR") { + throw new error_1.default({ + type: "BAD_INPUT_ERROR", + message: "Tenant not found", + }); + } const providerInputsFromStatic = options.staticThirdPartyProviders; const providerConfigsFromCore = tenantConfigRes.thirdParty.providers; const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic( diff --git a/lib/build/recipe/multitenancy/index.d.ts b/lib/build/recipe/multitenancy/index.d.ts index aee7c0dec..49bf39849 100644 --- a/lib/build/recipe/multitenancy/index.d.ts +++ b/lib/build/recipe/multitenancy/index.d.ts @@ -30,22 +30,27 @@ export default class Wrapper { static getTenant( tenantId: string, userContext?: any - ): Promise<{ - status: "OK"; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { - [key: string]: any; - }; - }>; + ): Promise< + | { + status: "OK"; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + coreConfig: { + [key: string]: any; + }; + } + | { + status: "TENANT_NOT_FOUND_ERROR"; + } + >; static listAllTenants( userContext?: any ): Promise<{ diff --git a/lib/build/recipe/multitenancy/types.d.ts b/lib/build/recipe/multitenancy/types.d.ts index d997b9783..54ba59c32 100644 --- a/lib/build/recipe/multitenancy/types.d.ts +++ b/lib/build/recipe/multitenancy/types.d.ts @@ -50,22 +50,27 @@ export declare type RecipeInterface = { getTenant: (input: { tenantId: string; userContext: any; - }) => Promise<{ - status: "OK"; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { - [key: string]: any; - }; - }>; + }) => Promise< + | { + status: "OK"; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + coreConfig: { + [key: string]: any; + }; + } + | { + status: "TENANT_NOT_FOUND_ERROR"; + } + >; listAllTenants: (input: { userContext: any; }) => Promise<{ diff --git a/lib/build/recipe/thirdparty/recipeImplementation.js b/lib/build/recipe/thirdparty/recipeImplementation.js index 9993f8d1e..628ca588f 100644 --- a/lib/build/recipe/thirdparty/recipeImplementation.js +++ b/lib/build/recipe/thirdparty/recipeImplementation.js @@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath")); const configUtils_1 = require("./providers/configUtils"); const recipe_1 = __importDefault(require("../multitenancy/recipe")); +const error_1 = __importDefault(require("./error")); function getRecipeImplementation(querier, providers) { return { signInUp: function ({ thirdPartyId, thirdPartyUserId, email, oAuthTokens, rawUserInfoFromProvider, tenantId }) { @@ -121,6 +122,12 @@ function getRecipeImplementation(querier, providers) { return __awaiter(this, void 0, void 0, function* () { const mtRecipe = recipe_1.default.getInstanceOrThrowError(); const tenantConfig = yield mtRecipe.recipeInterfaceImpl.getTenant({ tenantId, userContext }); + if (tenantConfig.status === "TENANT_NOT_FOUND_ERROR") { + throw new error_1.default({ + type: "BAD_INPUT_ERROR", + message: "Tenant not found", + }); + } const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic( tenantConfig.thirdParty.providers, providers diff --git a/lib/ts/recipe/multitenancy/api/implementation.ts b/lib/ts/recipe/multitenancy/api/implementation.ts index f96029366..9bb5b3a9d 100644 --- a/lib/ts/recipe/multitenancy/api/implementation.ts +++ b/lib/ts/recipe/multitenancy/api/implementation.ts @@ -1,5 +1,6 @@ import { APIInterface } from "../"; import { findAndCreateProviderInstance, mergeProvidersFromCoreAndStatic } from "../../thirdparty/providers/configUtils"; +import STError from "../error"; export default function getAPIInterface(): APIInterface { return { @@ -9,6 +10,13 @@ export default function getAPIInterface(): APIInterface { userContext, }); + if (tenantConfigRes.status === "TENANT_NOT_FOUND_ERROR") { + throw new STError({ + type: "BAD_INPUT_ERROR", + message: "Tenant not found", + }); + } + const providerInputsFromStatic = options.staticThirdPartyProviders; const providerConfigsFromCore = tenantConfigRes.thirdParty.providers; diff --git a/lib/ts/recipe/multitenancy/index.ts b/lib/ts/recipe/multitenancy/index.ts index d1fe1fe01..1cb5654cf 100644 --- a/lib/ts/recipe/multitenancy/index.ts +++ b/lib/ts/recipe/multitenancy/index.ts @@ -59,20 +59,25 @@ export default class Wrapper { static async getTenant( tenantId: string, userContext?: any - ): Promise<{ - status: "OK"; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { [key: string]: any }; - }> { + ): Promise< + | { + status: "OK"; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + coreConfig: { [key: string]: any }; + } + | { + status: "TENANT_NOT_FOUND_ERROR"; + } + > { const recipeInstance = Recipe.getInstanceOrThrowError(); return recipeInstance.recipeInterfaceImpl.getTenant({ tenantId, diff --git a/lib/ts/recipe/multitenancy/types.ts b/lib/ts/recipe/multitenancy/types.ts index 790c9c4b7..c38a8367e 100644 --- a/lib/ts/recipe/multitenancy/types.ts +++ b/lib/ts/recipe/multitenancy/types.ts @@ -69,20 +69,25 @@ export type RecipeInterface = { getTenant: (input: { tenantId: string; userContext: any; - }) => Promise<{ - status: "OK"; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { [key: string]: any }; - }>; + }) => Promise< + | { + status: "OK"; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + coreConfig: { [key: string]: any }; + } + | { + status: "TENANT_NOT_FOUND_ERROR"; + } + >; listAllTenants: (input: { userContext: any; }) => Promise<{ diff --git a/lib/ts/recipe/thirdparty/recipeImplementation.ts b/lib/ts/recipe/thirdparty/recipeImplementation.ts index c413764dd..c7f2a6fa0 100644 --- a/lib/ts/recipe/thirdparty/recipeImplementation.ts +++ b/lib/ts/recipe/thirdparty/recipeImplementation.ts @@ -3,6 +3,7 @@ import { Querier } from "../../querier"; import NormalisedURLPath from "../../normalisedURLPath"; import { findAndCreateProviderInstance, mergeProvidersFromCoreAndStatic } from "./providers/configUtils"; import MultitenancyRecipe from "../multitenancy/recipe"; +import STError from "./error"; export default function getRecipeImplementation(querier: Querier, providers: ProviderInput[]): RecipeInterface { return { @@ -116,6 +117,13 @@ export default function getRecipeImplementation(querier: Querier, providers: Pro const mtRecipe = MultitenancyRecipe.getInstanceOrThrowError(); const tenantConfig = await mtRecipe.recipeInterfaceImpl.getTenant({ tenantId, userContext }); + if (tenantConfig.status === "TENANT_NOT_FOUND_ERROR") { + throw new STError({ + type: "BAD_INPUT_ERROR", + message: "Tenant not found", + }); + } + const mergedProviders: ProviderInput[] = mergeProvidersFromCoreAndStatic( tenantConfig.thirdParty.providers, providers