I have a rout that requires authentication. In after model callback I redirect not authenticated user to the login route. Users can register on this route. After registration a user should confirm email. And after confirmation I should redirect user to requested route. I try save current route in afterModel hook (before redirect to login) in localStorege. but I can’t serialize transitation object or get requested url
It is not help to me. It is working only user sign in (not sign up). When user registers and clicks a link from a confirmation email, new instnce of ember app will be loaded and loginController will not have property ‘previousTransition’
It is not help to me. It is working only user sign in (not sign up). When user registers and clicks a link from a confirmation email, new instnce of ember app will be loaded and loginController will not have property ‘previousTransition’
Sounds like the link in the email needs to send them where they want to go, instead of the app root. So you could change the link, or embed the destination in a cookie which would picked up on the next access to the site, or store it in a session which persists for a while (which of course would require a session id in the link or a cookie).
But targetName returns ember’s route name. it will work only if route is static. But if route has dynamic segment (/order/:id) it isn’t working, because I should save params beside the route’s name.
And There are more complicated cases. For example, route may be nested to another routes with params or has queryParms.
I would be very happy if I had property ‘targetUrl’ in transition. Or if I could serialize transition’s object to JSON, save it in localStorage and deserialize
location.pathname is the location of where you landed. within that route is where you transition out and you save it by passing it as a query parameter.
scenario:
user attempts to go to /loans which requires authentication
user is redirected to /login?path=%2Floans
user authenticates then goes to the path if its defined (/loans in this case)
3 years later, and as far as I can tell, still no reliable/easy way to get the URL from from the Transition object.
Without any documentation, it’s hard to figure out how to use the generate method. Here’s an answer on stackoverflow that has working example invocation.
Personally, I simplified this approach with some lodash methods:
let params = merge({}, ...values(transition.params));
let url;
if(isEmpty(params)) {
url = transition.router.generate(transition.targetName);
} else {
url = transition.router.generate(transition.targetName, params);
}
(generate gets angry if you pass it {} for params)