Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attemptedTransition is never persisted #1559

Closed
elmisi opened this issue Mar 8, 2018 · 6 comments
Closed

attemptedTransition is never persisted #1559

elmisi opened this issue Mar 8, 2018 · 6 comments
Labels

Comments

@elmisi
Copy link

elmisi commented Mar 8, 2018

How to reproduce in dummy project:

  1. click on Protected Page link
  2. press CTRL + F5 to force Ember reload
  3. login
  4. app redirect to home / instead of /protected

Tested on Opera, Chrome and Firefox.

Probably the reason is that attemptedTransition is never persisted, it's easy to verify that inspecting the LocalStorage (or the cookies).

Furthermore I've tried to save by myself the attemptedTransition into the storage but it fails due to a circular reference.

@marcoow
Copy link
Member

marcoow commented Mar 13, 2018

attemptedTransition is a JavaScript object with references to other objects etc. We could never persist that and restore it afterwards.

@deepflame
Copy link
Contributor

We are having the same issue in connection with the Auth0 addon.

If it is not possible to persist and restore the 'attemptedTransition' could you please explain to the this line @marcoow https://github.com/simplabs/ember-simple-auth/blob/master/addon/mixins/authenticated-route-mixin.js#L89 ? Isn't that what this line should do? Or do you save the redirect url somewhere else?

@marcoow
Copy link
Member

marcoow commented Aug 2, 2018

@deepflame: that line sets the attemptedTransition of the session service but as soon as you restart the app (e.g. by reloading), the session object is destroyed of course. We could persist the route the attempted transition originally tried to transition to but there are all kinds of edge cases, e.g. when a model was passed to the transition etc.

@deepflame
Copy link
Contributor

@marcoow thanks for the swift reply!

I guess what our problem is is that the app redirects to the auth provider (in our case Auth0) and then restarts the whole app when it comes back with a token in the URL for authentication.

To solve this case I should just use the code in the fastboot case ( https://github.com/simplabs/ember-simple-auth/blob/master/addon/mixins/authenticated-route-mixin.js#L84-L87 ).

I will try this in connection with the Auth0 addon and fix it there. This is probably better than persisting sessions for all ember-simple-auth users.

@marcoow
Copy link
Member

marcoow commented Aug 2, 2018

Sure, you can always just override beforeModel.

@deepflame
Copy link
Contributor

Maybe this is helpful for anyone. I was overriding beforeModel like so:

  beforeModel(transition) {
    if (!this.get('session.isAuthenticated')) {
      const fastboot = getOwner(this).lookup('service:fastboot');
      const cookies = getOwner(this).lookup('service:cookies');

      const protocol = (() => {
        if (this.get('_isFastBoot')) {
          return fastboot.get('request.protocol');
        } else {
          return window.location.protocol.replace(/:/, '');
        }
      })();

      cookies.write('ember_simple_auth-redirectTarget', transition.intent.url, {
        path: '/',
        secure: protocol === 'https'
      });

      this.triggerAuthentication();
    } else {
      return this._super(...arguments);
    }
  },

Seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants