paweljw/bookstore-backend

View on GitHub
app/services/jwt_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

class JwtService
  def self.encode(payload)
    JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
  end

  def self.decode(token)
    body, = JWT.decode(token, Rails.application.secrets.secret_key_base,
                       true, algorithm: 'HS256')
    HashWithIndifferentAccess.new(body)
  rescue JWT::ExpiredSignature
    nil
  end
end