Check authentication on each request #26

Merged
atomaka merged 5 commits from guest-user into main 2024-08-16 19:59:30 -04:00
3 changed files with 22 additions and 7 deletions
Showing only changes of commit 28620e27d7 - Show all commits

View file

@ -1,9 +1,3 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user
private
def authenticate_user
Current.user = User.find_by(id: session[:current_user_id])
end
include Authenticatable
end

View file

@ -0,0 +1,13 @@
module Authenticatable
extend ActiveSupport::Concern
included do
before_action :authenticate_user
end
private
def authenticate_user
Current.user = User.find_by(id: session[:current_user_id])
end
end

View file

@ -17,6 +17,14 @@ class SessionsTest < ApplicationSystemTestCase
end
test "should destroy Session" do
visit new_session_url
fill_in "Email", with: @user.email
fill_in "Password", with: "secret"
click_on "Create Session"
assert_text "Session was successfully created"
visit root_url
click_on "Log out", match: :first