jeudi 20 août 2015

Ember model with session data

I have a problem with ember when I want to use a session data (companyId that is assigned to a user) in a model. I am using ember-cli and ember 0.13.1 with ember-simple-auth. Lets say I have a route called user/profile when I want to show information about company that the user is assigned to. In order to do that I need to retrieve a companyId that is assigned to a user from session and make a call with a model to my API. Currently the route for user/profile looks like that:

import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
    model: function() {
        return Ember.RSVP.hash({
                industries: this.store.findAll('industry'),
                industryroles: this.store.findAll('industryrole'),
                company: this.store.find('company',this.session.get('user.companyId'))
        });
    },
    setupController: function(controller, model) {
      controller.set('industries', model.industries);
            controller.set('industryroles', model.industryroles);
      controller.set('company', model.company);
  }
});

Everything works when you go to that route from different route, but when you are in user/profile route and you press F5 then the this.session.get('user.companyId') is undefined.

Does somebody have an idea how I can solve that problem ?

Best regards Pawel




Aucun commentaire:

Enregistrer un commentaire