I've been trying to validate a sign in process using Hanami (which is on top of dry-validation).
The point is: how to validate someting related to 2 fields: email + password?
I've read about custom predicates, but they seem to be only per field. Another concept is rule, but according to the examples it doesn't relate 2 things the way I need.
Here is my code:
module Web::Controllers::Sessions
class Create
include Web::Action
expose :validation # my standard way to show errors in the template
def call(params)
@validation = SigninValidator.new(params[:user]).validate
if @validation.success?
# more stuff here
end
end
end
class SigninValidator
include Hanami::Validations::Form
validations do
required(:email) { format?(EMAIL_REGEX)}
required(:password).filled(:str?)
# I GOT CONFUSED HERE
# how could I use someting like a repository and relate something like
# predicate + message for "email or password doesn't match"
end
end
Unfortunately the validations section in Hanami Guide is empty and I couldn't find a solution looking at the sources (hanami-validation and dry-validation).
Any help would be appreciated.