From 3e92d897659717ad2b600400ae1140f8cf7250b6 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Mon, 8 Apr 2024 03:46:41 -0700 Subject: [PATCH] Fix error when multiple accounts have a blank email address --- app/models/auth_user.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/auth_user.rb b/app/models/auth_user.rb index 15edcf19..21c33975 100644 --- a/app/models/auth_user.rb +++ b/app/models/auth_user.rb @@ -9,6 +9,11 @@ class AuthUser < AuthRecord length: {maximum: 30} 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 # (e.g. through the registration process), we create a matching User, too. And