Double response and logic error in account settings update
p5.js version
No response
What is your operating system?
None
Web browser and version
No response
Actual Behavior
In updateSettings() multiple code paths send a response but do not return, so:
- Social login user setting password:
saveUser(res, user)is called (sends 200), then execution continues and can send 401. - Password update:
await saveUser(res, user)sends response, then execution falls through andsaveUser()is called again in theelseblock.
Result: "Cannot set headers after they are sent", inconsistent client state, or users seeing errors despite success.
Location: server/controllers/user.controller/authManagement.ts lines 159–201
Expected Behavior
Each code path that sends a response should return immediately. Only one response per request.
Steps to reproduce
- Log in with a social account (e.g. Google) that has no password set.
- Go to Account settings and set a new password (no current password).
- Submit the form. Observe: success response may be sent, then 401 or double-response error.
- Alternatively: log in with email/password, change password, submit. Observe possible double response or header errors.
Snippet:
// authManagement.ts - updateSettings (simplified)
if (user.password === undefined) {
user.password = req.body.newPassword;
saveUser(res, user); // sends response, no return
}
if (!req.body.currentPassword) {
res.status(401).json({ ... }); // second response
return;
}
// ...
await saveUser(res, user); // line 177 - sends response
// no return - falls through to:
} else {
await saveUser(res, user); // line 201 - sends again
}
Hi @raclim! I'd love to work on this issue and submit the fix for it.
Thanks for spotting this! There's some ongoing backend work that may conflict with this, but when @raclim is able to check if it's still applicable, we could open it work work. Sorry for the delay!