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: Fix tenant id being passed in the wrong order for password update functions #636

Merged
merged 6 commits into from
Jul 14, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 15 additions & 16 deletions lib/build/recipe/dashboard/api/listTenants.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// @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[];
};
};
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<Response>;
export {};
19 changes: 18 additions & 1 deletion lib/build/recipe/dashboard/api/listTenants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,24 @@ 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 = {
tenantId: currentTenant.tenantId,
emailPassword: currentTenant.emailPassword,
passwordless: currentTenant.passwordless,
thirdParty: currentTenant.thirdParty,
};
finalTenants.push(modifiedTenant);
}
return {
status: "OK",
tenants: finalTenants,
};
});
}
exports.default = listTenants;
8 changes: 4 additions & 4 deletions lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ const userPasswordPut = (_, tenantId, options, userContext) =>
};
}
const passwordResetToken = yield emailpassword_1.default.createResetPasswordToken(
userId,
tenantId,
userId,
userContext
);
if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") {
// Techincally it can but its an edge case so we assume that it wont
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") {
Expand All @@ -119,18 +119,18 @@ const userPasswordPut = (_, tenantId, options, userContext) =>
};
}
const passwordResetToken = yield thirdpartyemailpassword_1.default.createResetPasswordToken(
userId,
tenantId,
userId,
userContext
);
if (passwordResetToken.status === "UNKNOWN_USER_ID_ERROR") {
// Techincally it can but its an edge case so we assume that it wont
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") {
Expand Down
8 changes: 8 additions & 0 deletions lib/build/recipe/dashboard/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
51 changes: 36 additions & 15 deletions lib/ts/recipe/dashboard/api/listTenants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ 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[];
};
};

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(
Expand All @@ -41,5 +42,25 @@ export default async function listTenants(
userContext: any
): Promise<Response> {
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 = {
tenantId: currentTenant.tenantId,
emailPassword: currentTenant.emailPassword,
passwordless: currentTenant.passwordless,
thirdParty: currentTenant.thirdParty,
};
finalTenants.push(modifiedTenant);
}

return {
status: "OK",
tenants: finalTenants,
};
}
8 changes: 4 additions & 4 deletions lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ 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
throw new Error("Should never come here");
}

const passwordResetResponse = await EmailPassword.resetPasswordUsingToken(
tenantId,
passwordResetToken.token,
newPassword,
tenantId,
userContext
);

Expand All @@ -108,17 +108,17 @@ 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
throw new Error("Should never come here");
}

const passwordResetResponse = await ThirdPartyEmailPassword.resetPasswordUsingToken(
tenantId,
passwordResetToken.token,
newPassword,
tenantId,
userContext
);

Expand Down
6 changes: 6 additions & 0 deletions lib/ts/recipe/dashboard/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
id: USER_API,
pathWithoutApiBasePath: new NormalisedURLPath(getApiPathWithDashboardBase(USER_API)),
Expand Down
Loading