I am using ember-simple-auth
(and ember-simple-auth-token
, but I think this is not relevant). Whenever a logged-in user reloads the page, the session is properly re-created. I have one problem, though: when the user enters the credentials, I am running this code:
// controllers/login.js
import Ember from 'ember';
import helpers from '../lib/helpers';
function refreshActiveUser(store, session) {
store.find('user', 'me').then(function(user) {
Ember.set(session, 'activeUser', user);
});
}
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
authenticate: function() {
var identification = this.get('model.identification'),
password = this.get('model.password'),
authenticator = 'authenticator:token',
store = this.get('store'),
session = this.get('session');
session.authenticate(authenticator, {identification, password}).then(function() {
refreshActiveUser(store, session);
});
}
},
});
But I do not know how to trigger my refreshActiveUser
on application reload. How can I listen to a "session initialized" event?