Skip to content

Commit 5059fb8

Browse files
committed
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.
1 parent fd305aa commit 5059fb8

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def user_signed_in?
1919

2020
def authenticate_user
2121
unless user_signed_in?
22-
redirect_to login_url, notice: "Please log in first"
22+
redirect_to github_auth_url(origin: request.url)
2323
end
2424
end
2525

app/controllers/sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def create
99
author.email = omni['info']['email']
1010
end
1111
self.current_user = @author
12-
redirect_to posts_url
12+
redirect_to request.env['omniauth.origin'] || posts_url
1313
end
1414
def login
1515
end

0 commit comments

Comments
 (0)