prime-simplereport icon indicating copy to clipboard operation
prime-simplereport copied to clipboard

[Bug] New misconfigured Api User is created when a user changes their own email

Open mehansen opened this issue 10 months ago • 1 comments

Description

When a user edits their own email to change it, the app creates a new Api User with their old email address. This Api User does not have a corresponding Okta user. This can be problematic if someone wants to add a user with the old email address because they'll get the an error that the user already exists. This caused a support request that required manual intervention from engineering to "create" the new user. It also means we're storing invalid users.

Steps to reproduce

How I reproduced in dev4

  1. Use a temp email tool to generate a new email [email protected].
  2. Logged in as myself to create a new user with admin permissions with the temp email.
  3. Used the temp email to log in and activate an account.
  4. Verified I could see this email in the ApiUser table and that we had an Okta account with the email.
  5. As the new admin, updated my email to be [email protected].
  6. Saw an error toast (I think this may only happen if the oktaMigrationEnabled flag is true).
  7. Verified the existing Api User was updated in the table with the new email and the Okta account also had the new email.
  8. Saw in Metabase a new Api User was created with the old email (see screenshot with created and updated timestamps).
Image

Expected behavior

When a user updates their email, we shouldn't create any additional Api Users.

Additional context

Reviewing logs for the support issue shows that we are hitting this line: https://github.com/CDCgov/prime-simplereport/blob/95185496cc9aea242fa28a5920d8ae619a2a080f/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java#L553 My guess is when the user updates their email some cached context with their identity also needs to be updated otherwise the app will create a new user for the old email still stored in the context.

mehansen avatar Feb 24 '25 23:02 mehansen

Additional context for prioritization: This bug was discovered as a part of investigating an issue raised by support and is something causes a headache when it happens.

DanielSass avatar Feb 26 '25 16:02 DanielSass