class UserSessionsController < ApplicationController
  skip_before_action :require_login, only: %i[new create]
  def new
    return redirect_to root_path, info: t('defaults.info') if logged_in?
  end

  def create
    @user = login(params[:email], params[:password])
    if @user
      redirect_back_or_to root_path, success: t('.success')
    else
      flash.now[:error] = t('.fail')
      render 'new'
    end
  end

  def destroy
    logout
    redirect_to root_path, success: t('.success')
  end
end
