p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

Double response and logic error in account settings update

Open Nixxx19 opened this issue 9 months ago • 2 comments

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:

  1. Social login user setting password: saveUser(res, user) is called (sends 200), then execution continues and can send 401.
  2. Password update: await saveUser(res, user) sends response, then execution falls through and saveUser() is called again in the else block.

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

  1. Log in with a social account (e.g. Google) that has no password set.
  2. Go to Account settings and set a new password (no current password).
  3. Submit the form. Observe: success response may be sent, then 401 or double-response error.
  4. 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
}

Nixxx19 avatar Feb 19 '26 03:02 Nixxx19

Hi @raclim! I'd love to work on this issue and submit the fix for it.

Nixxx19 avatar Feb 19 '26 03:02 Nixxx19

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!

ksen0 avatar May 12 '26 11:05 ksen0