(fix): Enable Volto Login to Redirect Back to Original Route After Authentication
There are situations where you may want the Volto login to appear on a route other than /login, as demonstrated in this example: https://github.com/collective/volto-authomatic/blob/a78f354e2c8fc4a41cf9d71d76a93f1d1627d268/src/index.js#L18. This implies that the Volto login should be accessible from any route invoked, thus the redirect after you are logged in should work also.
To achieve this, I removed the hardcoded /login route and implemented a regex to strip the last segment of the route where the login was initiated.
Deploy Preview for plone-components canceled.
| Name | Link |
|---|---|
| Latest commit | f9f6f611d083c0a52d9040024f3aeae8eb5c9c20 |
| Latest deploy log | https://app.netlify.com/sites/plone-components/deploys/671ad44d1cc91d0008d91b6d |
I think this is not a "fix" but a "feature". login was not broken. It could also be "breaking".
I have wanted this feature in Volto for a long time. Thanks for bringing it forward.
@stevepiercy, yes it will work also on a multilingual site, because the login route is still the last one
@dobri1408 Just thinking out loud, What about the cases where we have http://localhost:3000/login/page-one/page-two? (However its hard to imagine feasibility of these cases). As per current scenario we only replace paths ending with /login, given that we have Login component at that path. For custom paths its ideal to deal with it in its own component? 🤔
Perhaps I'm not understanding what this PR achieves, but can this not already be done by appending /login to any path? e.g. /my/long/path/login will return you to /my/long/path after you login.
This is works by the path being caught in routes.js and the props.location in Login.jsx that gets set by the router (from the wildcard catch in routes.js) is return_url which gets returned to after a successful login.
Perhaps I'm not understanding what this PR achieves, but can this not already be done by appending
/loginto any path? e.g./my/long/path/loginwill return you to/my/long/pathafter you login.
Confirmed!
https://demo.plone.org/vertical-spacing/grid-and-text/login
We should document this feature, as I never knew it existed. I imagine both end users and developers would want to know about it.