나는 건물중인 응용 프로그램에 대한 인증을 처리하기 위해 ember-simple-auth를 추가하고 있습니다. 현재 ApplicationRoute에서 모델을 사용하여 사이드 바 콘텐츠를로드하고 있습니다.ember.js + ember-simple-auth 인증 후 응용 프로그램 모델을로드하려면 어떻게해야합니까?
일부 데이터는 인증 토큰과 함께 반환되는 사용자 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' });
});
나는 비슷한 것을하고 결국 사용자 ID를 응답 패킷으로 파이핑했다. –