Skip to content


Browse files Browse the repository at this point in the history
Redirect users to original request after login
This commit does two things:

1. It passes `origin: request.url` into the `github_auth_url()` named
   route, which will preserve that request and return it with the
   OmniAuth hash.
2. The `create` action on the sessions_controller then either redirects
   to the originally requested URL or, if that doesn't exist, to the
   old default `posts_url` named route.
  • Loading branch information
karlstolley committed Apr 14, 2019
1 parent fd305aa commit 5059fb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -19,7 +19,7 @@ def user_signed_in?

def authenticate_user
unless user_signed_in?
redirect_to login_url, notice: "Please log in first"
redirect_to github_auth_url(origin: request.url)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Expand Up @@ -9,7 +9,7 @@ def create = omni['info']['email']
self.current_user = @author
redirect_to posts_url
redirect_to request.env['omniauth.origin'] || posts_url
def login
Expand Down

0 comments on commit 5059fb8

Please sign in to comment.