I'm building a Twitter based app in Ember-CLI and have a session initializer to ensure users are authenticated on each route. Users login via Twitter using the passport-twitter module for Express.js. I've done this before in a previous app and it's fine, but in this app I've noticed that every route reloads the page.
I've stripped everything out to just an h1 tag per route and it still reloads the page. As soon as I remove the initializer and beforeModel hook below however, everything works as expected with no page reload.
initializers/session.js :
name: 'session',
initialize: function(container, app) {
var Session = Ember.Object.extend({
user: null,
isAuthenticated: function() {
return this.get('user') !=null;
}.property('user')
});
app.register('session:main', Session);
app.inject('route', 'session', 'session:main');
app.inject('controller', 'session', 'session:main');
}
routes/application.js
beforeModel: function() {
var route = this;
var promise = this.store.find('user', {operation: 'authenticated'});
return promise.then(function(users) {
if (users && users.get('length') > 0) {
var user = users.get('firstObject');
route.set('session.user', user);
}
return users;
});
},
I've tried setting {singleton: true} in app.register just in case, but that doesn't work either.
I'm using a more recent version of Ember 1.11.1 and Ember-CLI 0.2.3 and I'm not sure how to even debug this. Any help much appreciated.
Aucun commentaire:
Enregistrer un commentaire