From 11f30700c3cf84a50d95c724f2320a012570c9be Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 17 Feb 2024 09:00:44 -0500 Subject: [PATCH] fix: use tx.Statement.Changed to ensure email is being changed before validating it --- db/models/user.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/models/user.go b/db/models/user.go index 925d9c9..bc1e61b 100644 --- a/db/models/user.go +++ b/db/models/user.go @@ -27,14 +27,14 @@ type User struct { } func (u *User) BeforeUpdate(tx *gorm.DB) error { - verify, err := getEmailVerfier().Verify(u.Email) - - if err != nil { - return err - } - - if !verify.Syntax.Valid { - return errors.New("email is invalid") + if tx.Statement.Changed("Email") { + verify, err := getEmailVerfier().Verify(u.Email) + if err != nil { + return err + } + if !verify.Syntax.Valid { + return errors.New("email is invalid") + } } return nil