summaryrefslogtreecommitdiff
path: root/app/controllers/api/authentications_controller.rb
blob: 3eb52c7a5f472eb6f91dca4705321424b72c258b (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
# frozen_string_literal: true

module Api
  # The controller that handles authentications.
  class AuthenticationsController < ApplicationController
    def create
      @token = logic(permitted_params).call

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

      render json: { error_message: 'Credenciales incorrectas' }, status: :unauthorized
    end

    def destroy
      current_user_account.session_key = nil
      current_user_account.save
    end

    private

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