【发布时间】:2014-06-12 11:11:59
【问题描述】:
我正在添加 ember-simple-auth 来处理我正在构建的应用程序的身份验证。目前在 ApplicationRoute 中,我正在使用模型来加载侧边栏内容。
某些数据取决于用户 URL 属性,该属性与身份验证令牌一起返回。
我正在重构我的代码以处理经过身份验证的用户的加载数据,但我不确定在哪里放置模型调用以加载侧边栏数据。
我认为在 isAuthenticated 属性上添加观察者以触发模型加载或采用我当前的路由并将它们包装在负责加载模型的资源中是否有意义?
申请途径
App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin,
{
model: function()
{
return Ember.RSVP.hash(
{
collections: Ember.$.getJSON(this.session.get('user.url') + '/collection'),
libraries: Ember.$.getJSON(ENV.api + '/library')
});
},
setupController: function(controller, model)
{
controller.set('libraries', model.libraries);
controller.set('collections', model.collections);
}
});
路线图
App.Router.map(function()
{
this.route('login');
// Authenticated Routes
this.route('my-account');
this.route('collection', { path: '/collection/:id' });
this.route('item.new', { path: '/item/new' });
this.route('item.edit', { path: '/item/:id' });
this.route('library', { path: '/:slug' });
});
【问题讨论】:
标签: authentication ember.js ember-simple-auth