Skip to content

Instantly share code, notes, and snippets.

@justincase
Created April 1, 2010 00:06
Show Gist options
  • Save justincase/351126 to your computer and use it in GitHub Desktop.
Save justincase/351126 to your computer and use it in GitHub Desktop.
Authlogic Multiple Sessions / Session Identifiers

Authlogic Multiple Sessions / Session Identifiers

This explanation seems to be lost in the current README

You’re asking: "why would I want multiple sessions?". Take this example:

You have an app where users login and then need to re-login to view / change their billing information. Similar to how Apple’s me.com works. What you could do is have the user login with their normal session, then have an entirely new session that represents their "secure" session. But wait, this is 2 users sessions. No problem:

# regular user session
@user_session = UserSession.new
@user_session.id
# => nil

# secure user session
@secure_user_session = UserSession.new(:secure)
@secure_user_session.id
# => :secure

This will keep everything separate. The :secure session will store its info in a separate cookie, separate session, etc. Just set the id and you are good to go. Need to retrieve the session?

@user_session = UserSession.find
@secure_user_session = UserSession.find(:secure)

For more information on ids checkout Authlogic::Session::Base#id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment