auth
auth copied to clipboard
fix: preserve user metadata when email_confirm=true in Confirm function
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
When creating a user with email_confirm: true, the Confirm function in internal/models/user.go overwrites the user's existing metadata instead of merging the email_verified: true flag with it.
#2088
Root cause
The current implementation calls UpdateUserMetaData with only {"email_verified": true}, which replaces the entire metadata object instead of merging with existing data.
Example of data loss
// Before email confirmation
{
"user_metadata": {
"name": "John Doe",
"age": 25,
"preferences": {
"theme": "dark",
"language": "en"
}
}
}
// After email confirmation (BROKEN - data lost!)
{
"user_metadata": {
"email_verified": true
}
}
What is the new behavior?
The Confirm function now properly preserves existing user metadata by:
- Reloading the user's latest state from the database to get the most recent metadata
- Merging the
email_verified: trueflag with existing metadata - Using the existing
UpdateUserMetaDatafunction to properly update without data loss
Example of correct behaviour:
// Before email confirmation
{
"user_metadata": {
"name": "John Doe",
"age": 25,
"preferences": {
"theme": "dark",
"language": "en"
}
}
}
// After email confirmation (FIXED - data preserved!)
{
"user_metadata": {
"name": "John Doe",
"age": 25,
"email_verified": true,
"preferences": {
"theme": "dark",
"language": "en"
}
}
}