Sha256: 5bcd63da467f3f49f04fbf5f23ebb722090090bb4f7b9fbebb055a9ac9604768

Contents?: true

Size: 818 Bytes

Versions: 2

Compression:

Stored size: 818 Bytes

Contents

# frozen_string_literal: true

module Devise
  module Api
    module TokensService
      class Refresh < Devise::Api::BaseService
        option :devise_api_token, type: Types.Instance(Devise.api.base_token_model.constantize)
        option :resource_owner, default: proc { devise_api_token.resource_owner }

        def call
          return Failure(error: :expired_refresh_token) if devise_api_token.refresh_token_expired?

          devise_api_token = yield create_devise_api_token
          Success(devise_api_token)
        end

        private

        def create_devise_api_token
          Devise::Api::TokensService::Create.new(resource_owner: resource_owner,
                                                 previous_refresh_token: devise_api_token.refresh_token).call
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise-api-0.2.0 app/services/devise/api/tokens_service/refresh.rb
devise-api-0.1.3 app/services/devise/api/tokens_service/refresh.rb