Ruby On Rails: Session Handling
Learn how to store user data in your session and clean it up upon logout. We recommend that you log in to follow this quickstart with examples configured for your account.
I want to explore a sample app2 minutes
Get a sample configured with your account settings or check it out on Github.
Store Session Data on Login
Upon successful authentication, OmniAuth sets the authentication hash of a request to
/auth/auth0/callback. To handle this request, add a new route in your routes file.
get "/auth/auth0/callback" => "auth0#callback"
Store the user information in the session in
# app/controllers/auth0_controller.rb def callback # This stores all the user information that came from Auth0 # and the IdP session[:userinfo] = request.env['omniauth.auth'] # Redirect to the URL you want after successful auth redirect_to '/dashboard' end
Clear Session on Logout
To clear out all the objects stored within the session, call the
reset_session method within the
logout_controller/logout method. Learn more about
# app/controllers/logout_controller.rb class LogoutController < ApplicationController include LogoutHelper def logout reset_session redirect_to logout_url.to_s end end