Skip to content
Permalink
Browse files

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 5059fb8e171df10e8014a7911e2f4175e812bf79
Showing with 2 additions and 2 deletions.
  1. +1 −1 app/controllers/application_controller.rb
  2. +1 −1 app/controllers/sessions_controller.rb
@@ -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)
end
end

@@ -9,7 +9,7 @@ def create
author.email = omni['info']['email']
end
self.current_user = @author
redirect_to posts_url
redirect_to request.env['omniauth.origin'] || posts_url
end
def login
end

0 comments on commit 5059fb8

Please sign in to comment.
You can’t perform that action at this time.