demarches-normaliennes/app/validators/jwt_token_validator.rb

12 lines
309 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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