Login and Logout should redirect back to from where request was made

#What is this about?

The Users.Login and Users.Logout methods redirect the user to the homepage, but should redirect the user to the page from which they came. E.g., if the user is trying to edit a bout and redirected to the login page, they should be redirected back to that bout to resume editing.

#How to fix it?

#Option 1 - Hidden fields

Add a hidden return_to field in the login form with a URL to redirect back to. Links to log in or out should include a return_to parameter. Then parse return_to from the URL or form (depending on situation) and redirect there.

#Option 2 - Cookies

Set a return_to cookie in middleware when redirecting to log in. Use JavaScript (?) to set cookies when clicking the log in or log out links. There might be another way to do this aside from using JavaScript; if not Option 1 is a better choice.

#When should this be fixed?

After core functionality is implemented. This is a convenience feature.

#Other information

Sourcehut does a great job with this and uses Option 1.

Assigned to
3 years ago
3 years ago
priority:med type:enhancement