Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:38:35+00:00 2026-06-14T14:38:35+00:00

I am using authlogic in my application. I also have split for A/B testing.

  • 0

I am using authlogic in my application.
I also have split for A/B testing.
I want split to use authlogic for authentication instead the BasicAuthentication or no authentication.

So I set my authentication class as middleware for the split sinatra app:

Split::Dashboard.use SinatraAuthlogic

Then this should be my authlogic middleware for:

class SinatraAuthlogic
  def initialize(app)
    @app = app
  end

  def call(env)
    if is_user_logged_in?
      puts @app.class
      response = @app.call env
    else
      response = Rack::Response.new
      response.redirect '/login'
      response.finish
    end
  end

private

  def is_user_logged_in?
    logged_in = UserSession.find && UserSession.find.user
  end
end

The question is what should I put in the is_user_logged_in in order to work with authlogic?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:38:36+00:00Added an answer on June 14, 2026 at 2:38 pm

    After some try I came up with this solution:

    class Authlogic::RackAdapter < Authlogic::ControllerAdapters::AbstractAdapter
      def initialize(env)
        request = Rack::Request.new(env)
        super(request)
        Authlogic::Session::Base.controller = self
      end
    end
    

    And in my middleware class I modified the ‘is_user_logged_in?’ method to this one:

    def is_user_logged_id?(env)
      begin
        adapter = Authlogic::RackAdapter.new(env)
        logged_in = UserSession.find && UserSession.find.user
        return true
      rescue Exception => e
        return false      
      end
    end
    

    This way I can find the user… However when the user isn’t logged in instead if nil I got an exception that is why I put the whole code in a rescue block…

    Any better aproaches are welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the authlogic gem for authentication. I have followed the steps at:
I am using authlogic with rails application for authentication. The perishable token is reset
I just recently update my Rails application to use Authlogic. The authentication works fine
I'm using authlogic with my user model, with the login field set to use
I've set up a new Rails app and am using Authlogic for authentication. I
I'm building a Rails application which uses Authlogic for authentication, which I've now set-up
I implemented an authentication system using authlogic, and have added password reset functionality as
I am using Authlogic for my user authentication, and would like yo add roles
I've been having trouble using cucumber and webrat to test authlogic-openid authentication in a
I am using authlogic (2.1.3) and declarative_authorization (0.4.1) to control access to my application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.