binarylogic / authlogic

A simple ruby authentication solution.
http://rdoc.info/projects/binarylogic/authlogic
MIT License
4.34k stars 638 forks source link

Must Activate Authlogic::Session::Base.controller #662

Closed drmwndr closed 5 years ago

drmwndr commented 5 years ago

I've created a base authentication system using Instructions of Authlogic ReadMe GitHub Repository. Now when i call UserSessions.new the following message is showed: " Authlogic::Session::Activation::NotActivatedError (You must activate the Authlogic::Session::Base.controller with a controller object before creating objects) "

I've readed some topics here about it, but none of the proposed solutions worked. Can someone help?

Rails 5.2.2, ruby 2.6.1

tiegz commented 5 years ago

Hi @drmwndr , are you initializing this in a Rails app, the Rails console, or Rails tests?

drmwndr commented 5 years ago

Hi! I've triend via console and on App running over development environment. Thank you for your interest! :)

Em qui, 21 de fev de 2019 às 12:00, Tieg Zaharia notifications@github.com escreveu:

Hi @drmwndr https://github.com/drmwndr , are you initializing this in a Rails app, the Rails console, or Rails tests?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/binarylogic/authlogic/issues/662#issuecomment-466051073, or mute the thread https://github.com/notifications/unsubscribe-auth/AD-0FvtdxpPWuGtqv06oqtjA3rBDMwK-ks5vPsA7gaJpZM4bHfwF .

tiegz commented 5 years ago

Ok, I usually have this [fix] in my ~/.irbrc:

controller.request = ActionController::TestRequest.new
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(controller)

Sidenote: wondering if there's a reason we don't always just do this in a Railtie since everyone runs into this problem.

NateJBeck commented 5 years ago

If your app was set up with Rails 5 API (using rails new foo --api), you may need to update ApplicationController.

ApplicationController < ActionController::API should be updated to ApplicationController < ActionController::Base

ActionController::Base has a few modules that (I imagine) AuthLogic requires that ActionController::API lacks. I went through as many combinations as I could but couldn't find the correct set of modules to include.

Modules in ActionController::Base https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/base.rb

Modules in ActionController::API https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/api.rb

jaredbeck commented 5 years ago

Closing, looks like this conversation is complete. If there's a concrete bug report or feature that someone can commit to working on, please open a new issue.