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?
Asked
Active
Viewed 29 times
1 Answers
2
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>

BugStrategy
- 77
- 4
-
`current_user` will only be available if it was set on the context before like `c.Set("current_user", user)`. So be sure have set the user somewhere – manuwell Jan 11 '23 at 21:25