From 052706877ae6924c59f707f112408f3e0e9918cf Mon Sep 17 00:00:00 2001 From: Divya Jagadish Date: Wed, 20 Dec 2023 16:40:04 -0800 Subject: [PATCH] Fix bug in Change Password --- lib/ui/api.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ui/api.ts b/lib/ui/api.ts index e372fcb..eb6db2f 100644 --- a/lib/ui/api.ts +++ b/lib/ui/api.ts @@ -740,16 +740,16 @@ router.put("/users/:id/password", async (ctx) => { return void (ctx.status = 403); } - const filter = and(authorizer.getFilter("users", 3), [ - "=", - ["PARAM", RESOURCE_IDS.users], - username, - ]); - const { value: res } = await db.query("users", filter).next(); - if (!res) return void (ctx.status = 404); - const newPassword = ctx.request.body.newPassword; + if (ctx.state.user) { + const filter = and(authorizer.getFilter("users", 3), [ + "=", + ["PARAM", RESOURCE_IDS.users], + username, + ]); + const { value: res } = await db.query("users", filter).next(); + if (!res) return void (ctx.status = 404); const validate = authorizer.getValidator("users", res); if (!validate("password", { password: newPassword })) { logUnauthorizedWarning(log);