Check authentication on each request #26
3 changed files with 15 additions and 1 deletions
|
@ -1,2 +1,9 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
before_action :authenticate_user
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def authenticate_user
|
||||||
|
Current.user = User.find_by(id: session[:current_user_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
3
app/models/current.rb
Normal file
3
app/models/current.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Current < ActiveSupport::CurrentAttributes
|
||||||
|
attribute :user
|
||||||
|
end
|
|
@ -19,7 +19,11 @@
|
||||||
<li class="mr-6"><%= link_to "Credit Card Bills", credit_card_bills_path, class: "text-white" %></li>
|
<li class="mr-6"><%= link_to "Credit Card Bills", credit_card_bills_path, class: "text-white" %></li>
|
||||||
<li class="mr-6"><%= link_to "Incomes", incomes_path, class: "text-white" %></li>
|
<li class="mr-6"><%= link_to "Incomes", incomes_path, class: "text-white" %></li>
|
||||||
<li class="mr-6"><%= link_to "Members", members_path, class: "text-white" %></li>
|
<li class="mr-6"><%= link_to "Members", members_path, class: "text-white" %></li>
|
||||||
<li class="mr-6"><%= link_to "Log out", session_path, data: {turbo_method: :delete}, class: "text-white" %></li>
|
<% if Current.user %>
|
||||||
|
<li class="mr-6"><%= link_to "Log out", session_path, data: {turbo_method: :delete}, class: "text-white" %></li>
|
||||||
|
<% else %>
|
||||||
|
<li class="mr-6"><%= link_to "Log in", new_session_path, class: "text-white" %></li>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue