After calling a custom authenticate method at login route, the action sessionAuthenticated is triggered at the application level (ApplicationRouteMixin).
ie:
sessionAuthenticated() {
this._super(...arguments);
let _this = this;
return this_loadUser().catch(function() {
_this.get('session').invalidate();
});
}
This works, however, if I want to preload extra data, sessionAuthenticated does not wait until all the promises are resolved. And since the beforeModel and afterModel hooks were already initially at the application route level, the only way this works reliably is when refreshing the page while session is active (logged in) which calls the beforeModel and afterModel hooks.
In short; when at the login route, calling authenticate, after successful authenticate the sessionAuthenticated action is triggered at the application route, but with extra data needed to be preloaded globally, at the application route level. The sessionAuthenticated doesn't see to wait until all promises are resolved.
NOTE: the answer is correct, however, the call to super will not work since Ember does not support calling super on asynchronous blocks, only synchronous.
Try to call this._super after your promise was fulfilled/rejected. Something like this:
sessionAuthenticated() {
let _this = this;
return this_loadUser().catch(function() {
_this.get('session').invalidate();
}).finally(function() {
_this._super(...arguments);
});
}