class Api::SessionsController < ApplicationController
  skip_before_action :verify_authenticity_token

  def create
    @user = User.find_by_credentials(user_params)

    if @user
      login!(@user)
      render "api/users/show"
    else
      @user = User.new
      render json: ["Invalid username and/or password"], status: 401
    end
  end

  def destroy
    if current_user
      logout!
      render json: {}
    else
      render json: ["No user is currently logged in"], status: 404
    end
  end
end
