How to check if user is registered in javascript

I have a signin shortcut that needs to be shown when the user is not logged in. Lightbox is fully implemented in javascript, fancybox and uses partial rails parts for html.

I see that the cookie is set in chrome at login, but document.cookieit seems to be empty. The reason was probably explained here.

How to achieve this in javascript / erb.

+5
source share
2 answers

Process it in the backend. If you do this with rails, be sure to use and abuse current_user, because it will be your best friend.

Then, in partial, you can have something like this

<% if current_user %>
     <p>Welcome <%= current_user.username %>!</p>
<% else %>
     <p>Please <%= link_to 'sign in', login_path %></p>
<% end %>

Rails, Ruby on Rails

+2

, Jordan Scales, ... DRYing if @current_user.nil?

+2

All Articles