ESA: issues with redirection

Hey! I’ve got my /login route setup like this:

import Route from '@ember/routing/route';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
import OAuth2ImplicitGrantCallbackRouteMixin from 'ember-simple-auth/mixins/oauth2-implicit-grant-callback-route-mixin';

export default Route.extend(UnauthenticatedRouteMixin, OAuth2ImplicitGrantCallbackRouteMixin, {
    authenticator: 'authenticator:oauth2'

And authentication works! When my server redirects the user to “{host}:{port}/login#access_token=abc”, they do get authenticated.

 * {@inheritdoc}
public function authenticated(Request $request, SteamUser $steam)
    // Get or create the authenticating user from their steam details.
    $user = $this->get_or_create_user($steam);
    return response()->redirectTo('/login#access_token=' . $user->api_token);

However, it does not redirect them to the “routeIfAlreadyAuthenticated”. For that to happen, I must manually click refresh, in which they get redirected. It should work like I have, right? The two mixins should not override each other?

Any help is appreciated!!

I think what you’re looking for is routeAfterAuthentication. That’s the route the Ember app is redirected to after authentication. routeIfAlreadyAuthenticated is when the session is already authenticated and a route with the UnauthenticatedRouteMixin is transitioned to. (Typically when the user visits /login when they are already signed in.)

See here in the source.

Thanks! I figured it out, the issue was with super not being called as I used await before calling super (which we can’t anymore), hence the redirection never occured:

 async sessionAuthenticated() {
    await this._loadCurrentUser();

The fix was pretty easy, just declare a variable pointing to super before await is called.

async sessionAuthenticated() {
    let _super = this._super;
    await this._loadCurrentUser();, ...arguments);

I made a pull request to update ESA’s “manage current user” guide to reflect this.

In this code, you’re still not calling the parent implementation before calling this._loadCurrentUser. I once stumbled into something similar with this._super not working reliably with async functions (I think) but I’m no longer sure what the exact issue was.