Skip to content

Commit

Permalink
fix: handle tenant not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 17, 2023
1 parent f3f5044 commit 290356c
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 60 deletions.
12 changes: 12 additions & 0 deletions lib/build/recipe/multitenancy/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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(
Expand Down
37 changes: 21 additions & 16 deletions lib/build/recipe/multitenancy/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
37 changes: 21 additions & 16 deletions lib/build/recipe/multitenancy/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
7 changes: 7 additions & 0 deletions lib/build/recipe/thirdparty/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/ts/recipe/multitenancy/api/implementation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIInterface } from "../";
import { findAndCreateProviderInstance, mergeProvidersFromCoreAndStatic } from "../../thirdparty/providers/configUtils";
import STError from "../error";

export default function getAPIInterface(): APIInterface {
return {
Expand All @@ -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;

Expand Down
33 changes: 19 additions & 14 deletions lib/ts/recipe/multitenancy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 19 additions & 14 deletions lib/ts/recipe/multitenancy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
8 changes: 8 additions & 0 deletions lib/ts/recipe/thirdparty/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 290356c

Please sign in to comment.