How do I sign in a user in Clearance from a custom router?
-
13-11-2019 - |
Question
I'm adding Omniauth to my app where I'm using Clearance for regular authentication. I've run into a wall trying to sign in a user programatically.
I'm looking for something like sign_in_and_redirect
from Devise, but can't find it in Clearance.
I've tried using sign_in <User>
and calling redirect_to root_path
right after. However, when the root page loads, the current_user
is not set.
Does anyone know how to do this? Does anyone know of a tutorial for adding Omniauth to Clearance?
Thanks
Solution
I haven't used Clearance, I usually either roll my own authentication or use Devise, but a quick look through the code tells me that sign_in(@user) does nothing more than set @current_user=@user so you need some way to persist that information before you redirect. Clearance appears to use a remember_token for this, so I'd try (untested) something like this:
sign_in(@user)
cookies['remember_token'] = @user.remember_token
redirect_to(root_path)