How can I check if a visitor is logged in from within a template using the Go Buffalo web framework? Specifically, I am working on a project that utilizes the Buffalo framework and I need to be able to determine if a user is currently logged in or not, and I would like to do this within one of my templates. Are there any built-in methods or functions provided by Buffalo that can be used to accomplish this task?
I found out that I can use current_user
, like this
<div class="auth-center">
<%= if (current_user) { %>
<h1><%= current_user.email %></h1>
<a href="/signout" data-method="delete">sign out</a>
<% } else { %>
<a href="/signin" class="btn btn-primary">sign in</a>
<a href="/users/new" class="btn btn-success">register</a>
<% } %>
</div>