# ESA: issues with redirection

**URL:** <https://discuss.emberjs.com/t/esa-issues-with-redirection/16926>\
**Category:** Routing\
**Created:** [August 6, 2019, 8:57pm UTC](https://discuss.emberjs.com/t/esa-issues-with-redirection/16926 "2019-08-06T20:57:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExpDev07](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/expdev07/32/16628_2.png) [@ExpDev07](https://discuss.emberjs.com/u/ExpDev07)\
**Post date:** [August 6, 2019, 8:57pm UTC](https://discuss.emberjs.com/t/esa-issues-with-redirection/16926/1 "2019-08-06T20:57:48Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [August 9, 2019, 8:23pm UTC](https://discuss.emberjs.com/t/esa-issues-with-redirection/16926/2 "2019-08-09T20:23:44Z")

</div>

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](https://github.com/simplabs/ember-simple-auth/blob/76e0eacf94f1d1d4d1194b3ef93ceae0bc5e000e/addon/configuration.js#L67-L93).

---

<div class="post-metadata">

**Author:** ![ExpDev07](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/expdev07/32/16628_2.png) [@ExpDev07](https://discuss.emberjs.com/u/ExpDev07)\
**Post date:** [August 9, 2019, 11:21pm UTC](https://discuss.emberjs.com/t/esa-issues-with-redirection/16926/3 "2019-08-09T23:21:31Z")

</div>

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:

```auto
 async sessionAuthenticated() {
    await this._loadCurrentUser();
    this._super(...arguments);
}

```

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();
    _super.call(this, ...arguments);
}

```

I made a pull request to update ESA’s “manage current user” guide to reflect this. [https://github.com/simplabs/ember-simple-auth/pull/1924/files](https://github.com/simplabs/ember-simple-auth/pull/1924/files)

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [August 11, 2019, 12:44pm UTC](https://discuss.emberjs.com/t/esa-issues-with-redirection/16926/4 "2019-08-11T12:44:05Z")

</div>

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.
