Log in using the Devise program outside the controller

I am trying to figure out a way to sign a user when using Devise. I know this is possible from a controller using the following helper:

sign_in(:user, user)

Unfortunately, this helper does not work when called from a service or initializer (I have an initializer where I can identify the user from, but I want to be able to log in). Is there any way to do this outside the controller? Maybe use a warden?

+4
source share
1 answer
class SomeService
  include Devise::Controllers::Helpers

  def process(user)
    sign_in(user)
  end
end
0
source

Source: https://habr.com/ru/post/1654068/


All Articles