fix: use tx.Statement.Changed to ensure email is being changed before validating it

This commit is contained in:
Derrick Hammer 2024-02-17 09:00:44 -05:00
parent c076d219d0
commit 11f30700c3
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 8 deletions

View File

@ -27,15 +27,15 @@ type User struct {
}
func (u *User) BeforeUpdate(tx *gorm.DB) error {
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
}