Fix error when multiple accounts have a blank email address

This commit is contained in:
Emi Matchu 2024-04-08 03:46:41 -07:00
parent ed89380152
commit 3e92d89765

View file

@ -9,6 +9,11 @@ class AuthUser < AuthRecord
length: {maximum: 30} length: {maximum: 30}
has_one :user, foreign_key: :remote_id, inverse_of: :auth_user has_one :user, foreign_key: :remote_id, inverse_of: :auth_user
# If the email is blank, ensure that it's `nil` rather than an empty string,
# or else the database's uniqueness constraint will object to multiple users
# who all have the empty string as their email.
before_validation { self.email = nil if email.blank? }
# It's important to keep AuthUser and User in sync. When we create an AuthUser # It's important to keep AuthUser and User in sync. When we create an AuthUser
# (e.g. through the registration process), we create a matching User, too. And # (e.g. through the registration process), we create a matching User, too. And