check email already in use

This commit is contained in:
xfarrow 2024-02-18 12:14:24 +01:00
parent 46229ac247
commit a31e6b4c66

View File

@ -59,6 +59,16 @@ async function registerPerson(req, res){
const hashPasswordPromise = bcrypt.hash(req.body.password, 10);
try{
// Check whether e-mail exists already (enforced by database constraints)
const existingUser = await knex('Person')
.where('email', req.body.email)
.first();
if(existingUser){
return res.status(409).json({ error: "E-mail already in use" });
}
// We need to insert either both in the "Person" table
// and in the "ActivationLink" one, or in neither
await knex.transaction(async (tr) => {