demarches-normaliennes/app/validators/jwt_token_validator.rb

10 lines
278 B
Ruby
Raw Permalink Normal View History

2020-07-08 17:00:21 +02:00
class JwtTokenValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
JWT.decode value, nil, false
rescue
2023-03-15 17:22:55 +01:00
record.errors.add attribute, :invalid, message: (options[:message] || "n'est pas un jeton valide")
2020-07-08 17:00:21 +02:00
end
end
end