admin管理员组文章数量:1401461
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
2 Answers
Reset to default 3Handle 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?
本文标签: jqueryHow do I check if user is logged in javascriptStack Overflow
版权声明:本文标题:jquery - How do I check if user is logged in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744287927a2598970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论