From 8bb1c128df6528823401b428da87e9c316535054 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Thu, 13 Jul 2023 10:51:52 +0530 Subject: [PATCH 1/5] Remove core config from dashboard tenants list response --- .../recipe/dashboard/api/listTenants.d.ts | 32 ++++++------ lib/build/recipe/dashboard/api/listTenants.js | 15 +++++- lib/ts/recipe/dashboard/api/listTenants.ts | 51 +++++++++++++------ 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/lib/build/recipe/dashboard/api/listTenants.d.ts b/lib/build/recipe/dashboard/api/listTenants.d.ts index 6633e6532..f2c21dcd7 100644 --- a/lib/build/recipe/dashboard/api/listTenants.d.ts +++ b/lib/build/recipe/dashboard/api/listTenants.d.ts @@ -1,23 +1,23 @@ // @ts-nocheck import { APIInterface, APIOptions } from "../types"; import { ProviderConfig } from "../../thirdparty/types"; +declare type TenantListTenantType = { + tenantId: string; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + coreConfig?: any; +}; export declare type Response = { status: "OK"; - tenants: { - tenantId: string; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { - [key: string]: any; - }; - }[]; + tenants: TenantListTenantType[]; }; export default function listTenants(_: APIInterface, __: string, ___: APIOptions, userContext: any): Promise; +export {}; diff --git a/lib/build/recipe/dashboard/api/listTenants.js b/lib/build/recipe/dashboard/api/listTenants.js index 7cad0b06b..aa0c3a955 100644 --- a/lib/build/recipe/dashboard/api/listTenants.js +++ b/lib/build/recipe/dashboard/api/listTenants.js @@ -40,7 +40,20 @@ const multitenancy_1 = __importDefault(require("../../multitenancy")); function listTenants(_, __, ___, userContext) { return __awaiter(this, void 0, void 0, function* () { let tenantsRes = yield multitenancy_1.default.listAllTenants(userContext); - return tenantsRes; + let finalTenants = []; + if (tenantsRes.status !== "OK") { + return tenantsRes; + } + for (let i = 0; i < tenantsRes.tenants.length; i++) { + let currentTenant = tenantsRes.tenants[i]; + let modifiedTenant = Object.assign({}, currentTenant); + delete modifiedTenant["coreConfig"]; + finalTenants.push(modifiedTenant); + } + return { + status: "OK", + tenants: finalTenants, + }; }); } exports.default = listTenants; diff --git a/lib/ts/recipe/dashboard/api/listTenants.ts b/lib/ts/recipe/dashboard/api/listTenants.ts index c0ac1549b..aee1ec402 100644 --- a/lib/ts/recipe/dashboard/api/listTenants.ts +++ b/lib/ts/recipe/dashboard/api/listTenants.ts @@ -16,22 +16,25 @@ import { APIInterface, APIOptions } from "../types"; import Multitenancy from "../../multitenancy"; import { ProviderConfig } from "../../thirdparty/types"; +type TenantListTenantType = { + tenantId: string; + emailPassword: { + enabled: boolean; + }; + passwordless: { + enabled: boolean; + }; + thirdParty: { + enabled: boolean; + providers: ProviderConfig[]; + }; + // This optional any is to allow deleting the key before sending the response to the frontend + coreConfig?: any; +}; + export type Response = { status: "OK"; - tenants: { - tenantId: string; - emailPassword: { - enabled: boolean; - }; - passwordless: { - enabled: boolean; - }; - thirdParty: { - enabled: boolean; - providers: ProviderConfig[]; - }; - coreConfig: { [key: string]: any }; - }[]; + tenants: TenantListTenantType[]; }; export default async function listTenants( @@ -41,5 +44,23 @@ export default async function listTenants( userContext: any ): Promise { let tenantsRes = await Multitenancy.listAllTenants(userContext); - return tenantsRes; + let finalTenants: TenantListTenantType[] = []; + + if (tenantsRes.status !== "OK") { + return tenantsRes; + } + + for (let i = 0; i < tenantsRes.tenants.length; i++) { + let currentTenant = tenantsRes.tenants[i]; + let modifiedTenant: TenantListTenantType = { + ...currentTenant, + }; + delete modifiedTenant["coreConfig"]; + finalTenants.push(modifiedTenant); + } + + return { + status: "OK", + tenants: finalTenants, + }; } From 8c3f8f0b99a2045a9a6a21338c4af9fea534898f Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Thu, 13 Jul 2023 11:43:52 +0530 Subject: [PATCH 2/5] Fix tenant id being passed in the wrong order for password update functions --- .../recipe/dashboard/api/userdetails/userPasswordPut.js | 8 ++++---- .../recipe/dashboard/api/userdetails/userPasswordPut.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js b/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js index 136b55cf1..e43b3c046 100644 --- a/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js +++ b/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js @@ -87,8 +87,8 @@ const userPasswordPut = (_, tenantId, options, userContext) => }; } const passwordResetToken = yield emailpassword_1.default.createResetPasswordToken( - userId, tenantId, + userId, userContext ); if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") { @@ -96,9 +96,9 @@ const userPasswordPut = (_, tenantId, options, userContext) => throw new Error("Should never come here"); } const passwordResetResponse = yield emailpassword_1.default.resetPasswordUsingToken( + tenantId, passwordResetToken.token, newPassword, - tenantId, userContext ); if (passwordResetResponse.status === "RESET_PASSWORD_INVALID_TOKEN_ERROR") { @@ -119,8 +119,8 @@ const userPasswordPut = (_, tenantId, options, userContext) => }; } const passwordResetToken = yield thirdpartyemailpassword_1.default.createResetPasswordToken( - userId, tenantId, + userId, userContext ); if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") { @@ -128,9 +128,9 @@ const userPasswordPut = (_, tenantId, options, userContext) => throw new Error("Should never come here"); } const passwordResetResponse = yield thirdpartyemailpassword_1.default.resetPasswordUsingToken( + tenantId, passwordResetToken.token, newPassword, - tenantId, userContext ); if (passwordResetResponse.status === "RESET_PASSWORD_INVALID_TOKEN_ERROR") { diff --git a/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts b/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts index dc37669ba..9f2d2cfed 100644 --- a/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts +++ b/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts @@ -72,7 +72,7 @@ export const userPasswordPut = async ( }; } - const passwordResetToken = await EmailPassword.createResetPasswordToken(userId, tenantId, userContext); + const passwordResetToken = await EmailPassword.createResetPasswordToken(tenantId, userId, userContext); if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") { // Techincally it can but its an edge case so we assume that it wont @@ -80,9 +80,9 @@ export const userPasswordPut = async ( } const passwordResetResponse = await EmailPassword.resetPasswordUsingToken( + tenantId, passwordResetToken.token, newPassword, - tenantId, userContext ); @@ -108,7 +108,7 @@ export const userPasswordPut = async ( }; } - const passwordResetToken = await ThirdPartyEmailPassword.createResetPasswordToken(userId, tenantId, userContext); + const passwordResetToken = await ThirdPartyEmailPassword.createResetPasswordToken(tenantId, userId, userContext); if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") { // Techincally it can but its an edge case so we assume that it wont @@ -116,9 +116,9 @@ export const userPasswordPut = async ( } const passwordResetResponse = await ThirdPartyEmailPassword.resetPasswordUsingToken( + tenantId, passwordResetToken.token, newPassword, - tenantId, userContext ); From 43a8bce49d5f47ea00c0395ea4c3bb41ff5cece4 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Thu, 13 Jul 2023 12:38:20 +0530 Subject: [PATCH 3/5] Add user PUT api to list --- lib/build/recipe/dashboard/recipe.js | 8 ++++++++ lib/ts/recipe/dashboard/recipe.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/build/recipe/dashboard/recipe.js b/lib/build/recipe/dashboard/recipe.js index 8e3d21479..21048b788 100644 --- a/lib/build/recipe/dashboard/recipe.js +++ b/lib/build/recipe/dashboard/recipe.js @@ -147,6 +147,14 @@ class Recipe extends recipeModule_1.default { disabled: false, method: "post", }, + { + id: constants_1.USER_API, + pathWithoutApiBasePath: new normalisedURLPath_1.default( + utils_1.getApiPathWithDashboardBase(constants_1.USER_API) + ), + disabled: false, + method: "put", + }, { id: constants_1.USER_API, pathWithoutApiBasePath: new normalisedURLPath_1.default( diff --git a/lib/ts/recipe/dashboard/recipe.ts b/lib/ts/recipe/dashboard/recipe.ts index 6bc8318fd..dcc3fbf51 100644 --- a/lib/ts/recipe/dashboard/recipe.ts +++ b/lib/ts/recipe/dashboard/recipe.ts @@ -167,6 +167,12 @@ export default class Recipe extends RecipeModule { disabled: false, method: "post", }, + { + id: USER_API, + pathWithoutApiBasePath: new NormalisedURLPath(getApiPathWithDashboardBase(USER_API)), + disabled: false, + method: "put", + }, { id: USER_API, pathWithoutApiBasePath: new NormalisedURLPath(getApiPathWithDashboardBase(USER_API)), From 6f2c79367836b7634f9d6551d265ad6242cefc4d Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Fri, 14 Jul 2023 09:48:52 +0530 Subject: [PATCH 4/5] Update tenant list API logic --- lib/build/recipe/dashboard/api/listTenants.d.ts | 1 - lib/build/recipe/dashboard/api/listTenants.js | 8 ++++++-- lib/ts/recipe/dashboard/api/listTenants.ts | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/build/recipe/dashboard/api/listTenants.d.ts b/lib/build/recipe/dashboard/api/listTenants.d.ts index f2c21dcd7..3b7422fa8 100644 --- a/lib/build/recipe/dashboard/api/listTenants.d.ts +++ b/lib/build/recipe/dashboard/api/listTenants.d.ts @@ -13,7 +13,6 @@ declare type TenantListTenantType = { enabled: boolean; providers: ProviderConfig[]; }; - coreConfig?: any; }; export declare type Response = { status: "OK"; diff --git a/lib/build/recipe/dashboard/api/listTenants.js b/lib/build/recipe/dashboard/api/listTenants.js index aa0c3a955..a6918eb8e 100644 --- a/lib/build/recipe/dashboard/api/listTenants.js +++ b/lib/build/recipe/dashboard/api/listTenants.js @@ -46,8 +46,12 @@ function listTenants(_, __, ___, userContext) { } for (let i = 0; i < tenantsRes.tenants.length; i++) { let currentTenant = tenantsRes.tenants[i]; - let modifiedTenant = Object.assign({}, currentTenant); - delete modifiedTenant["coreConfig"]; + let modifiedTenant = { + tenantId: currentTenant.tenantId, + emailPassword: currentTenant.emailPassword, + passwordless: currentTenant.passwordless, + thirdParty: currentTenant.thirdParty, + }; finalTenants.push(modifiedTenant); } return { diff --git a/lib/ts/recipe/dashboard/api/listTenants.ts b/lib/ts/recipe/dashboard/api/listTenants.ts index aee1ec402..0383a48de 100644 --- a/lib/ts/recipe/dashboard/api/listTenants.ts +++ b/lib/ts/recipe/dashboard/api/listTenants.ts @@ -28,8 +28,6 @@ type TenantListTenantType = { enabled: boolean; providers: ProviderConfig[]; }; - // This optional any is to allow deleting the key before sending the response to the frontend - coreConfig?: any; }; export type Response = { @@ -53,9 +51,11 @@ export default async function listTenants( for (let i = 0; i < tenantsRes.tenants.length; i++) { let currentTenant = tenantsRes.tenants[i]; let modifiedTenant: TenantListTenantType = { - ...currentTenant, + tenantId: currentTenant.tenantId, + emailPassword: currentTenant.emailPassword, + passwordless: currentTenant.passwordless, + thirdParty: currentTenant.thirdParty, }; - delete modifiedTenant["coreConfig"]; finalTenants.push(modifiedTenant); } From 9cde16501fe1edb56637e2778728b3032c247413 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Fri, 14 Jul 2023 09:56:29 +0530 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9b01e719..e92bb2806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Fixes + +- Fixed an issue where certain Dashboard API routes would return a 404 for Hapi + ## [14.1.3] - 2023-07-03 ### Changes