I have a Ruby on Rails 3.0.7 application and my user authentication with devise
but and I have an alternative sign up
and sign in
methods, I allow my users to sign up using their Facebook
account then I save that login info in my users
table the same one that devise uses to register and login users.
Steps
Koala
) I give the user a generic password.I'm just missing the 3rd step because I want to keep using the current_user
helper and the user_signed_in?
helper too.
So how do I tell devise to sign in this user automatically from my other controller?
I saw something like that on this question Devise: Have multiple controllers handle user sessions and it logs my user in but leads me to an blank page...
Devise is a well known solution for authentication in Rails applications. It's full featured (it not only adds authentication but also password recovery, email changing, session timeout, locking, ip tracking, etc.) and can be expanded to add even more (like JWT authentication).
The devise gem is basically based on a warden gem, which gives an opportunity to build authorization direct on a Ruby Rack Stack. This gem is pretty straightforward and well documented. Warden fetches a request data and checks if the request includes valid credentials, according to a defined strategy.
Devise offers a bunch of helpers, two of which are these:
sign_in(resource_or_scope, *args)
sign_in_and_redirect(resource_or_scope, *args)
You can use these from any controller.
EDIT
If using sign_in
already works for you but leaves the user on a blank page, check your logfile to see if there is a redirect going on, and where it redirects to. Or just make the redirect explicit by using the second of the helpers above.
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