Wait until method is done then call super in mixin

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() {
     * 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!



Nevermind, this was an issue with Ember not allowing us to call super after await anymore (for some reason, I just could not find this anywhere). I’ve updated the ESA guide: https://github.com/simplabs/ember-simple-auth/pull/1924.

ESA mixins tap into beforeModel but your beforeModel never calls this._super(...arguments) And that would cause issue as far as I understand it.

If it were me I would block on the beforeModel():

async beforeModel() {
  await this._loadCurrentUser();
  await this._super(...arguments);

Read my reply… the issue was not with the beforeModel