I have a rails 3 app using devise for authentication, and want to use javascript to see if a user is logged in. What's the best way to do this?
Since Devise is based on Warden, you can use Warden's callbacks to set an additional cookie that will be visible from js (unlike the server only session cookie), e.g in your devise.rb:
Warden::Manager.after_set_user do |user,auth,opts|
auth.cookies[:signed_in] = 1
end
Warden::Manager.before_logout do |user,auth,opts|
auth.cookies.delete :signed_in
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With