Search code examples
ruby-on-railsrubysessionauthlogic

rails authlogic can't find current_user (nil) after using http basic authentication


I am using

rails => 3.0.20

authlogic => 3.0.3

before using http basic authentication it is all okay. But after using it, after login successfully with 'http basic user name and pass' I have to log in with application user name and password which is retrived from database. It is also sucessfully done. Then it is redirected to a default method which requires current user. But current user returns nil. UserSession.find also returns nil

any idea about why session objects return nil ?


Solution

  • If you are using authlogic and rails 3, I believe it could be work if you add below code in user_session.rb model:

     class UserSession < Authlogic::Session::Base
        allow_http_basic_auth false
     end
    

    Not sure why this is a problem with this Rails/Authlogic/HTTP combination, but anyways, the fix was to add this one-liner to your UserSession model

    Thumbs up to Chris Irish here I found this in his blog.