jquery - How do I check if user is logged in javascript - Stack Overflow

I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely imp

I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely implemented in javascript, fancybox and uses rails partials for html.

I can see the cookie is set in chrome when logged in, but document.cookie seems to return empty. The reason probably has been explained here

How do I achieve this in javascript / erb.

I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely implemented in javascript, fancybox and uses rails partials for html.

I can see the cookie is set in chrome when logged in, but document.cookie seems to return empty. The reason probably has been explained here

How do I achieve this in javascript / erb.

Share Improve this question edited May 23, 2017 at 12:09 CommunityBot 11 silver badge asked Jun 3, 2012 at 6:10 ShaggyInjunShaggyInjun 2,9832 gold badges34 silver badges54 bronze badges 2
  • 4 Does anyone actually have a js-based answer for this, unlike both answers listed below? – lulalala Commented Jul 30, 2012 at 8:24
  • Probably impossible. See stackoverflow./a/29739169/6594668 or use cookies instead. – prograils Commented Apr 4, 2017 at 11:48
Add a ment  | 

2 Answers 2

Reset to default 3

Handle this in the backend. If you're doing this with rails, be sure to use and abuse current_user, because it will be your best friend.

Then in your partial, you're free to have something like this

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

Rails Sessions, Ruby on Rails Tutorial

same approach as Jordan Scales said, but making it simpler ... DRYing if @current_user.nil?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744287928a4566888.html

相关推荐

  • jquery - How do I check if user is logged in javascript - Stack Overflow

    I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely imp

    8天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信