How to authenticate using warden.authenticate!

user557818 picture user557818 · Dec 30, 2010 · Viewed 11.6k times · Source

I would like to do a 'sign-in or register' on the fly when posting a comment to my forum. I am using Devise/Warden.

I want to do something like this:

user = warden.authenticate!(params[:email], params[:password])
sign_in(:user, user)

Can anyone give me some tips on how to do this?

Thanks!

Answer

Elle picture Elle · Mar 30, 2015

Warden has a set_user helper method. So you should be able to do:

warden.set_user(@user, scope: :user)

You could probably define a controller helper method, to sign in the user and redirect them to your desired path

More information is available at: https://github.com/hassox/warden/wiki/Authenticated-session-data