Fix: Update users_by_email with all fields

The security_data field, which includes the WasEmailVerified
flag, must be preserved during email updates. The update
query now includes all fields in the users_by_email table.

https://codeberg.org/mapleopentech/monorepo/issues/1#issuecomment-8725011
This commit is contained in:
Bartlomiej Mika 2025-12-05 15:38:46 -05:00
parent 598a7d3fad
commit 5156835e80

View file

@ -62,13 +62,17 @@ func (impl userStorerImpl) UpdateByID(ctx context.Context, user *dom_user.User)
// Delete old email entry // Delete old email entry
batch.Query(`DELETE FROM users_by_email WHERE email = ?`, existingUser.Email) batch.Query(`DELETE FROM users_by_email WHERE email = ?`, existingUser.Email)
// Insert new email entry // Insert new email entry with ALL fields including security_data
// IMPORTANT: security_data contains WasEmailVerified flag which must be preserved
batch.Query(` batch.Query(`
INSERT INTO users_by_email ( INSERT INTO users_by_email (
email, id, first_name, last_name, status, created_at email, id, first_name, last_name, name, lexical_name,
) VALUES (?, ?, ?, ?, ?, ?)`, role, status, timezone, created_at, modified_at,
user.Email, user.ID, user.FirstName, user.LastName, profile_data, security_data, metadata
user.Status, user.CreatedAt, ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
user.Email, user.ID, user.FirstName, user.LastName, user.Name, user.LexicalName,
user.Role, user.Status, user.Timezone, user.CreatedAt, user.ModifiedAt,
profileDataJSON, securityDataJSON, metadataJSON,
) )
} else { } else {
// Just update the existing email entry // Just update the existing email entry