Often users will attempt to navigate to or refresh a page after their session has run out (or they never had one). Redirecting to login is trivial, but after successful login we want to take the user back to the page they were on. In order to do that, we need to hold onto the original path while they log in. This can be done in a few ways:
next or redirect arg in query string
- cookie or local storage
- use
Referer header on request to login route
I like the query string option. Cookie and local storage make me nervous because they're opaque to the user and you have to worry about expiration.
We can't use Referer properly because routing is (at least sometimes) client-side, so there are no request headers. We could use a referrer key on the React Router redirect to prop, but to me that's just a more opaque and less reliable version of using the query string.
Often users will attempt to navigate to or refresh a page after their session has run out (or they never had one). Redirecting to login is trivial, but after successful login we want to take the user back to the page they were on. In order to do that, we need to hold onto the original path while they log in. This can be done in a few ways:
nextorredirectarg in query stringRefererheader on request to login routeI like the query string option. Cookie and local storage make me nervous because they're opaque to the user and you have to worry about expiration.
We can't use
Refererproperly because routing is (at least sometimes) client-side, so there are no request headers. We could use areferrerkey on the React Router redirecttoprop, but to me that's just a more opaque and less reliable version of using the query string.