나는 ApplicationRoute에서 사용자가 인증을 losts 때 나는엠버 - 간단한 인증 ApplicationRoute 모델 기능
model: function() {
return Ember.RSVP.hash({
user: this.store.find('gsUser').then(function(data) {
return data.get('content')[0]
})
});
},
setupController: function(controller, model) {
this.controllerFor('user').set('content', model.user);
}
을 사용하고 페이지를 열고, 엠버 - 간단한 인증의 고전적인 설정을 가지고있다. ApplicationRoute :: model이 먼저 실행되고 서버가 401을 반환하고 다른 실행이 중지됩니다.
GET http://localhost:8000/app_dev.php/api/1/users.json 401 (Unauthorized)
Error while loading route: undefined
model
은 인증이 성공한 경우에만 해고되어야합니다.
나는 sessionAuthenticationSucceeded
이 있다는 것을 알았지 만 나는 듣는 모든 방법을 시도했지만 아무도 일하지 않았다. 사용자가 성공적으로 인증되면이 이벤트를 수신하고 서버에서 데이터를 가져 오는 방법은 무엇입니까?
11/06 22시 57분 UPDATE :
App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin, {
skipModelLoading: false,
beforeModel: function() {
this.set('skipModelLoading', !this.get('session').get('isAuthenticated'));
},
model: function() {
if (this.get('skipModelLoading')) {
return;
}
return Ember.RSVP.hash({
user: this.store.find('gsUser').then(function(data) {
return data.get('content')[0]
})
});
},
setupController: function(controller, model) {
if (this.get('skipModelLoading')) {
return;
}
this.controllerFor('user').set('content', model.user);
}
});
을 사용하면 사용자가 있는지 확인 함 수동으로 또는'AuthenticatedRouteMixin' (나중에 로그인 경로에도 적용되기 때문에 후자가 될 수 있습니다)에서 혼합하여 경로의'beforeModel'에서 인증됩니까? – marcoow
@marcoow : beforeModel : 시도, 내가 전환 중지 할 수 있습니다 기능 (전환) { 경우 ( transition.abort {) (썩 ('세션')) 'IsAuthenticated는'(나가!.) } } 하지만 다음에해야 할 일은 무엇입니까?) 로그인 경로로의 전환은 무한 리디렉션이므로 잘못 작동합니다. 올바른 방법으로 어떻게해야합니까? –
네, 그게 문제입니다. 세션이 로그인 경로를 포함한 모든 경로에 적용되는 것처럼 애플리케이션 경로의 'model' 메소드에서 인증되도록 요구할 수 없습니다. – marcoow