Session.content
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?
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
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
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.
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
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.
Have you tried the solution here simplabs/ember-simple-auth#345? It seems Torii does not implement restore very well.
I have not tried that yet, did it work for you @ethanharstad ? I haven't had much time since the new school semester started
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
};
It has worked for me as well.
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:
Nice solution!!
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.
I'd be interested still.. thanks!
Sorry for the delay, I've been swamped with schoolwork, so if anyone makes any progress keep us posted!
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.