diff --git a/packages/worker/src/api/routes/global/tests/auth.spec.ts b/packages/worker/src/api/routes/global/tests/auth.spec.ts index 59b6fe5869..e984649507 100644 --- a/packages/worker/src/api/routes/global/tests/auth.spec.ts +++ b/packages/worker/src/api/routes/global/tests/auth.spec.ts @@ -229,7 +229,7 @@ describe("/api/global/auth", () => { ) expect(res.body).toEqual({ - message: "Cannot reset password.", + message: "Password change is disabled for this user", status: 400, }) } @@ -261,8 +261,13 @@ describe("/api/global/auth", () => { ) // convert to account owner now that password has been requested - const account = structures.accounts.ssoAccount() as CloudAccount - mocks.accounts.getAccount.mockReturnValueOnce( + const account: CloudAccount = { + ...structures.accounts.ssoAccount(), + budibaseUserId: user._id!, + email: user.email, + tenantId: config.getTenantId(), + } + mocks.accounts.getAccountByTenantId.mockReturnValueOnce( Promise.resolve(account) ) diff --git a/packages/worker/src/sdk/auth/auth.ts b/packages/worker/src/sdk/auth/auth.ts index e670a7d091..5ddccdd2b1 100644 --- a/packages/worker/src/sdk/auth/auth.ts +++ b/packages/worker/src/sdk/auth/auth.ts @@ -74,14 +74,14 @@ export const reset = async (email: string) => { * Perform the user password update if the provided reset code is valid. */ export const resetUpdate = async (resetCode: string, password: string) => { + const { userId } = await cache.passwordReset.getCode(resetCode) + let user = await userSdk.db.getUser(userId) + const validation = security.validatePassword(password) if (!validation.valid) { throw new HTTPError(validation.error, 400) } - const { userId } = await cache.passwordReset.getCode(resetCode) - - let user = await userSdk.db.getUser(userId) user.password = password user = await userSdk.db.save(user)