summaryrefslogtreecommitdiff
path: root/app/controllers/api/authentications_controller.rb
blob: 85ef3d4b2fb583b389d9d37cc653389f0c335475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Api
  # The controller that handles authentications.
  class AuthenticationsController < ApplicationController
    AUTHENTICATION_ERROR = 'Credenciales incorrectas'

    def create
      @logic = logic.new(permitted_params)
      @token = @logic.call

      render json: @token, status: :ok and return if @token

      render json: { message: AUTHENTICATION_ERROR }, status: :unauthorized
    end

    def destroy; end

    def refresh; end

    private

    def permitted_params
      params.require(:credentials).permit(:email, :password)
    end

    def service
      @service = Services::AuthenticationService.new(permitted_params)
    end
  end
end