class JsonWebToken
  ALGORITHM = 'HS256'.freeze
  class << self
    def encode(payload, exp = 24.hours.from_now)
      payload[:exp] = exp.to_i
      JWT.encode(payload, Rails.application.secrets.secret_token, ALGORITHM)
    end

    def decode(token)
      body = JWT.decode(token, Rails.application.secrets.secret_token, true, algorithm: ALGORITHM).first
      HashWithIndifferentAccess.new body
    rescue StandardError
      nil
    end
  end
  end
