Skip to content
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

fix: handle tenant not found error #639

Merged
merged 3 commits into from
Jul 17, 2023
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
6 changes: 6 additions & 0 deletions lib/build/recipe/multitenancy/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function getAPIInterface() {
tenantId,
userContext,
});
if (tenantConfigRes === undefined) {
throw new Error("Tenant not found");
}
const providerInputsFromStatic = options.staticThirdPartyProviders;
const providerConfigsFromCore = tenantConfigRes.thirdParty.providers;
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
Expand All @@ -55,6 +58,9 @@ function getAPIInterface() {
clientType,
userContext
);
if (providerInstance === undefined) {
throw new Error("should never come here"); // because creating instance from the merged provider list itself
}
finalProviderList.push({
id: providerInstance.id,
name: providerInstance.config.name,
Expand Down
35 changes: 19 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,25 @@ 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;
};
}
| undefined
>;
static listAllTenants(
userContext?: any
): Promise<{
Expand Down
3 changes: 3 additions & 0 deletions lib/build/recipe/multitenancy/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ function getRecipeInterface(querier) {
),
{}
);
if (response.status === "TENANT_NOT_FOUND_ERROR") {
return undefined;
}
return response;
});
},
Expand Down
35 changes: 19 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,25 @@ 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;
};
}
| undefined
>;
listAllTenants: (input: {
userContext: any;
}) => Promise<{
Expand Down
8 changes: 7 additions & 1 deletion lib/build/recipe/thirdparty/api/authorisationUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ function authorisationUrlAPI(apiImplementation, tenantId, options, userContext)
tenantId,
userContext,
});
const provider = providerResponse.provider;
if (providerResponse === undefined) {
throw new error_1.default({
type: error_1.default.BAD_INPUT_ERROR,
message: `the provider ${thirdPartyId} could not be found in the configuration`,
});
}
const provider = providerResponse;
let result = yield apiImplementation.authorisationUrlGET({
provider,
redirectURIOnProviderDashboard,
Expand Down
8 changes: 7 additions & 1 deletion lib/build/recipe/thirdparty/api/signinup.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ function signInUpAPI(apiImplementation, tenantId, options, userContext) {
clientType,
userContext,
});
const provider = providerResponse.provider;
if (providerResponse === undefined) {
throw new error_1.default({
type: error_1.default.BAD_INPUT_ERROR,
message: `the provider ${thirdPartyId} could not be found in the configuration`,
});
}
const provider = providerResponse;
let result = yield apiImplementation.signInUpPOST({
provider,
redirectURIInfo,
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdparty/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export default class Wrapper {
thirdPartyId: string,
clientType: string | undefined,
userContext?: any
): Promise<{
status: "OK";
provider: TypeProvider;
}>;
): Promise<TypeProvider | undefined>;
static manuallyCreateOrUpdateUser(
tenantId: string,
thirdPartyId: string,
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/configUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export declare function findAndCreateProviderInstance(
thirdPartyId: string,
clientType: string | undefined,
userContext: any
): Promise<TypeProvider>;
): Promise<TypeProvider | undefined>;
export declare function mergeConfig(staticConfig: ProviderConfig, coreConfig: ProviderConfig): ProviderConfig;
export declare function mergeProvidersFromCoreAndStatic(
providerConfigsFromCore: ProviderConfig[],
Expand Down
6 changes: 1 addition & 5 deletions lib/build/recipe/thirdparty/providers/configUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ exports.mergeProvidersFromCoreAndStatic = exports.mergeConfig = exports.findAndC
const _1 = require(".");
const custom_1 = __importDefault(require("./custom"));
const utils_1 = require("./utils");
const error_1 = __importDefault(require("../error"));
function getProviderConfigForClient(providerConfig, clientConfig) {
return Object.assign(Object.assign({}, providerConfig), clientConfig);
}
Expand Down Expand Up @@ -85,10 +84,7 @@ function findAndCreateProviderInstance(providers, thirdPartyId, clientType, user
return providerInstance;
}
}
throw new error_1.default({
type: error_1.default.BAD_INPUT_ERROR,
message: `the provider ${thirdPartyId} could not be found in the configuration`,
});
return undefined;
});
}
exports.findAndCreateProviderInstance = findAndCreateProviderInstance;
Expand Down
8 changes: 4 additions & 4 deletions lib/build/recipe/thirdparty/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ 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 === undefined) {
throw new Error("Tenant not found");
}
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
tenantConfig.thirdParty.providers,
providers
Expand All @@ -131,10 +134,7 @@ function getRecipeImplementation(querier, providers) {
clientType,
userContext
);
return {
status: "OK",
provider,
};
return provider;
});
},
};
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdparty/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ export declare type RecipeInterface = {
tenantId: string;
clientType?: string;
userContext: any;
}): Promise<{
status: "OK";
provider: TypeProvider;
}>;
}): Promise<TypeProvider | undefined>;
signInUp(input: {
thirdPartyId: string;
thirdPartyUserId: string;
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdpartyemailpassword/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export default class Wrapper {
thirdPartyId: string,
clientType: string | undefined,
userContext?: any
): Promise<{
status: "OK";
provider: TypeProvider;
}>;
): Promise<TypeProvider | undefined>;
static thirdPartyManuallyCreateOrUpdateUser(
tenantId: string,
thirdPartyId: string,
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdpartyemailpassword/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ export declare type RecipeInterface = {
clientType?: string;
tenantId: string;
userContext: any;
}): Promise<{
status: "OK";
provider: TypeProvider;
}>;
}): Promise<TypeProvider | undefined>;
thirdPartySignInUp(input: {
thirdPartyId: string;
thirdPartyUserId: string;
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdpartypasswordless/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export default class Wrapper {
thirdPartyId: string,
clientType: string | undefined,
userContext?: any
): Promise<{
status: "OK";
provider: TypeProvider;
}>;
): Promise<TypeProvider | undefined>;
static thirdPartyManuallyCreateOrUpdateUser(
tenantId: string,
thirdPartyId: string,
Expand Down
5 changes: 1 addition & 4 deletions lib/build/recipe/thirdpartypasswordless/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ export declare type RecipeInterface = {
clientType?: string;
tenantId: string;
userContext: any;
}): Promise<{
status: "OK";
provider: TypeProvider;
}>;
}): Promise<TypeProvider | undefined>;
createCode: (
input: (
| {
Expand Down
9 changes: 9 additions & 0 deletions lib/ts/recipe/multitenancy/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default function getAPIInterface(): APIInterface {
userContext,
});

if (tenantConfigRes === undefined) {
throw new Error("Tenant not found");
}

const providerInputsFromStatic = options.staticThirdPartyProviders;
const providerConfigsFromCore = tenantConfigRes.thirdParty.providers;

Expand All @@ -27,6 +31,11 @@ export default function getAPIInterface(): APIInterface {
clientType,
userContext
);

if (providerInstance === undefined) {
throw new Error("should never come here"); // because creating instance from the merged provider list itself
}

finalProviderList.push({
id: providerInstance.id,
name: providerInstance.config.name,
Expand Down
31 changes: 17 additions & 14 deletions lib/ts/recipe/multitenancy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,23 @@ 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 };
}
| undefined
> {
const recipeInstance = Recipe.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.getTenant({
tenantId,
Expand Down
4 changes: 4 additions & 0 deletions lib/ts/recipe/multitenancy/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default function getRecipeInterface(querier: Querier): RecipeInterface {
{}
);

if (response.status === "TENANT_NOT_FOUND_ERROR") {
return undefined;
}

return response;
},

Expand Down
31 changes: 17 additions & 14 deletions lib/ts/recipe/multitenancy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,23 @@ 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 };
}
| undefined
>;
listAllTenants: (input: {
userContext: any;
}) => Promise<{
Expand Down
9 changes: 8 additions & 1 deletion lib/ts/recipe/thirdparty/api/authorisationUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ export default async function authorisationUrlAPI(
userContext,
});

const provider = providerResponse.provider;
if (providerResponse === undefined) {
throw new STError({
type: STError.BAD_INPUT_ERROR,
message: `the provider ${thirdPartyId} could not be found in the configuration`,
});
}

const provider = providerResponse;
let result = await apiImplementation.authorisationUrlGET({
provider,
redirectURIOnProviderDashboard,
Expand Down
Loading
Loading