EmberAuthTutorial icon indicating copy to clipboard operation
EmberAuthTutorial copied to clipboard

Session.content

Open aethant opened this issue 11 years ago • 15 comments

Hi, I really enjoyed your tutorial, however I'm having an issue with Session.content. Perhaps I've missed a step. When I refresh the page, I'm still logged in, but the all the data in Session.content gets wiped out.

What did I miss?

aethant avatar Dec 29 '14 20:12 aethant

Hey,

Good point, I haven't noticed that before. I think it has something to do with Ember-Simple-Auth Store or Authorizers.

Initially I did look into Ember-Simple-Auth Authroizers but I wasn't able to get it working. I have a suspicion if we moved the code that gets from G+ API into a custom authorizer it would re-get the information upon each reload. You would likely need to store the authData.token somewhere else or specify to persist on reloads or multiple tabs

If you manage to figure it out please let me know and I will incorporate it to the tutorial

Frozenfire92 avatar Dec 29 '14 21:12 Frozenfire92

Thinking about this further, an easier (although not the best) solution would be to check if session.content is null/undefined, if so then call

this.get('session').invalidate();

which would force the user to login again

Frozenfire92 avatar Dec 29 '14 23:12 Frozenfire92

That's not really an effective solution, because it will require everyone to log in -constantly-. In testing this with session.content, it logs in, provides the info. I can click through to one route, and then the data disappears. It would be a massive irritation from the user's standpoint.

I'm trying to figure out how to get the authorizer to work. Or something like reopen. I'm not sure.

aethant avatar Dec 30 '14 14:12 aethant

It shouldn't lose the info between routes, only reloads?

As I said not the best solution, if you manage to get an authorizer working please let me know as I'd be interested to update.

Maybe you could store the token info somewhere else and call the g+ api if the session info is gone? I think the authorizer is the best route however, just don't have time at the moment to look into it further

Frozenfire92 avatar Dec 30 '14 14:12 Frozenfire92

I'll see what I can do.

I was surprised it wasn't just reloads, too, but maybe there's a timeout or something. If I recall, somewhere in simple-auth it wipes the login info so it isn't stored for an extended period of time. Maybe that's connected to the disappearing session.content.

aethant avatar Dec 30 '14 14:12 aethant

Have you tried the solution here simplabs/ember-simple-auth#345? It seems Torii does not implement restore very well.

ethanharstad avatar Jan 26 '15 20:01 ethanharstad

I have not tried that yet, did it work for you @ethanharstad ? I haven't had much time since the new school semester started

Frozenfire92 avatar Jan 26 '15 23:01 Frozenfire92

I just tried that fix (by adding an initializer) and it worked for me:

import Ember from 'ember';
import AuthenticatorTorii from 'simple-auth-torii/authenticators/torii';

export var initialize = function() {
  AuthenticatorTorii.reopen({
    // session data has changed or app that already had persisted session was opened
    restore: function(data) {
      // doing nothing, cause none of torii providers return anything when session is
      // invalidated and it clears the session
      var resolveData = data || {};
      this.provider = resolveData.provider;
      return new Ember.RSVP.Promise(function(resolve) { resolve(resolveData); });
    }
  });
};

export default {
  name: 'reopen-authenticator-torii',
  before: 'simple-auth-torii',
  initialize: initialize
};

davidsteinberger avatar Jan 26 '15 23:01 davidsteinberger

It has worked for me as well.

ethanharstad avatar Jan 27 '15 00:01 ethanharstad

Awesome! What directory was this added in @dave8401 ?

I will try and get a chance to test and update the tutorial soon. If someone wanted to make a PR I would gladly accept :smile:

Frozenfire92 avatar Jan 27 '15 00:01 Frozenfire92

Nice solution!!

aethant avatar Jan 27 '15 16:01 aethant

Is a PR still needed? I was thinking of forking and extending to include session management with an API as well anyway if I have some time this weekend.

ethanharstad avatar Feb 18 '15 16:02 ethanharstad

I'd be interested still.. thanks!

aethant avatar Feb 19 '15 12:02 aethant

Sorry for the delay, I've been swamped with schoolwork, so if anyone makes any progress keep us posted!

Frozenfire92 avatar Feb 24 '15 01:02 Frozenfire92

Using the initializer I get logged out upon reload.

"ember-cli-simple-auth": "0.8.0-beta.2" "ember-cli-simple-auth-torii": "0.8.0-beta.2"

I'd already had an initializer, although it contained just:

container.register("simple-auth-authenticator:torii", ToriiAuthenticator);

Strangely enough, when I comment that line out, leaving just the reopen(), everything still works (but I'm still logged out on reload). I can't recall where I saw that the container.register() line was necessary. Perhaps it no longer is.

brianally avatar May 02 '15 19:05 brianally