DEV: Add logging and rescue when user already exists and connecting via DiscourseConnect (#22833)

This is happening because despite the user already existing in the forum, the `SingleSignOnRecord` doesn't exist and "require_activation" is set on the provider, causing us to skip looking for the email, and resulting in us creating a new User then seeing Validation failed: Primary email has already been taken when DiscourseConnect is attempting to make a new account.
This commit is contained in:
Natalie Tay 2023-07-28 02:53:33 +08:00 committed by GitHub
parent ad05924bdf
commit 173de8afe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -267,7 +267,16 @@ class DiscourseConnect < DiscourseConnectBase
ReviewableUser.set_approved_fields!(user, Discourse.system_user)
end
user.save!
begin
user.save!
rescue ActiveRecord::RecordInvalid => e
if SiteSetting.verbose_discourse_connect_logging
Rails.logger.error(
"Verbose SSO log: User creation failed. External id: #{external_id}, New User (user_id: #{user.id}) Params: #{user_params} User Params: #{user.attributes} User Errors: #{user.errors.full_messages} Email: #{user.primary_email.attributes} Email Error: #{user.primary_email.errors.full_messages}",
)
end
raise e
end
if SiteSetting.verbose_discourse_connect_logging
Rails.logger.warn(