module Care class JwtService def decode(token) decoded_token = JWT.decode(token, public_key, true, algorithm: 'RS256') HashWithIndifferentAccess.new(decoded_token[0]) end def encode(payload) JWT.encode(payload, secret_key, 'RS256') end private def public_key key = File.read(ENV['JWT_SECRET_PATH']) OpenSSL::PKey::RSA.new(key) end def secret_key key = File.read(ENV['JWT_SECRET_PATH']) OpenSSL::PKey::RSA.new(key) end end end