Fixes email update validation logic
This commit is contained in:
parent
b4be479d02
commit
8dc60b41ff
1 changed files with 10 additions and 8 deletions
|
|
@ -599,11 +599,11 @@ const app = new Elysia({
|
||||||
const values = [];
|
const values = [];
|
||||||
|
|
||||||
if (body.email) {
|
if (body.email) {
|
||||||
// Enforce unique email constraint
|
const existingUser = await db
|
||||||
const existingUser = await db.query(
|
.query("SELECT id FROM users WHERE email = ?")
|
||||||
"SELECT id FROM users WHERE email = ?",
|
.as(User)
|
||||||
).get(body.email);
|
.get(body.email);
|
||||||
if (existingUser && existingUser.id !== user.id) {
|
if (existingUser && existingUser.id.toString() !== user.id) {
|
||||||
set.status = 409;
|
set.status = 409;
|
||||||
return { message: "Email already in use." };
|
return { message: "Email already in use." };
|
||||||
}
|
}
|
||||||
|
|
@ -615,9 +615,11 @@ const app = new Elysia({
|
||||||
values.push(await Bun.password.hash(body.newPassword));
|
values.push(await Bun.password.hash(body.newPassword));
|
||||||
}
|
}
|
||||||
|
|
||||||
db.query(
|
if (fields.length < 1) {
|
||||||
`UPDATE users SET ${fields.map((field) => `${field}=?`).join(", ")} WHERE id=?`,
|
db.query(
|
||||||
).run(...values, user.id);
|
`UPDATE users SET ${fields.map((field) => `${field}=?`).join(", ")} WHERE id=?`,
|
||||||
|
).run(...values, user.id);
|
||||||
|
}
|
||||||
|
|
||||||
return redirect(`${WEBROOT}/`, 302);
|
return redirect(`${WEBROOT}/`, 302);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue