// Hooks of the User.
Hooks of the User.
// Hooks of the User .
func (User) Hooks() []ent.Hook {
	return []ent.Hook{
		hook.On(
			func(next ent.Mutator) ent.Mutator {
				return hook.UserFunc(func(ctx context.Context, m *gen.UserMutation) (ent.Value, error) {
					if password, ok := m.Password(); ok && len(password) <= 20 {
						hashPassword, err := hash.Make(password)
						if err != nil {
							return nil, fmt.Errorf("failed to hash password: %w", err)
						}
						m.SetPassword(string(hashPassword))
					}
					return next.Mutate(ctx, m)
				})
			},
			ent.OpCreate|ent.OpUpdate|ent.OpUpdateOne,
		),
	}
}
func ( User ) Hooks ( ) [ ] ent . Hook { return [ ] ent . Hook { hook . On ( func ( next ent . Mutator ) ent . Mutator { return hook . UserFunc ( func ( ctx context . Context , m * gen . UserMutation ) ( ent . Value , error ) { if password , ok := m . Password ( ) ; ok && len ( password ) <= 20 { hashPassword , err := hash . Make ( password ) if err != nil { return nil , fmt . Errorf ( " " , err ) } m . SetPassword ( string ( hashPassword ) ) } return next . Mutate ( ctx , m ) } ) } , ent . OpCreate | ent . OpUpdate | ent . OpUpdateOne , ) , } }
Hooks of the User.
Hooks of the User .