@ExpDev07 wrote:
Hey, I have followed ESA’s “manage current user” guide and have come up with the following:
import Route from '@ember/routing/route'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; import { inject as service } from '@ember/service'; export default Route.extend(ApplicationRouteMixin, { /** * The user that's currently logged in. */ currentUser: service(), beforeModel() { // Load the current user here so that it becomes available in all routes. return this._loadCurrentUser(); }, /** * Called when the session gets authenticated. */ sessionAuthenticated() { this._loadCurrentUser(); this._super(...arguments); }, /** * Loads the currently logged in user. Invalidates the session if the loading fails. */ _loadCurrentUser() { return this.currentUser.load().catch(() => this.session.invalidate()); } });
However, in
sessionAuthenticated()
, super (handles redirection) won’t be called if I mark the function as async. So what I need is, to wait until the current user is loaded before I call super. I’ve tried something like:
this._loadCurrentUser().then(() => this._super(...arguments));
But that didn’t seem to work either. I appreciate any help!
Thanks,
ExpDev
Posts: 2
Participants: 1