# frozen_string_literal: true module Api # The controller to generate new tokens. class RefreshTokensController < AuthenticatedController def create @current_user_account.update_attribute(:session_key, SecureRandom.hex(16)) @token = { token: service.call(DateTime.current + 30), refresh: service.call(authentication_token[0]['exp']) } render json: @token, status: :ok end def service_params { email: @current_user_account.email, role: @current_user_account.role, session_key: @current_user_account.session_key } end def service @service ||= Services::TokenGenerationService.new(service_params) end end end