[英]Ember Simple Auth transition after login
I have login code on my application route, as per examples in the docs, but the call to authenticate does not seem to return a promise. 根据文档中的示例,我在应用程序路由中具有登录代码,但是进行身份验证的调用似乎未返回承诺。 The response I get in 'then' is undefined. 我在“然后”中得到的响应是不确定的。 Therefore the transition does not work. 因此过渡不起作用。 I have to manually refresh the page, and then the top redirect is called. 我必须手动刷新页面,然后调用顶部重定向。
import Ember from 'ember';
// Make 'session' available throughout the application
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
redirect: function () {
this.transitionTo('orders');
},
actions: {
authenticate: function () {
var data = {
identification: this.controller.get('identification'),
password: this.controller.get('password')
};
this.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', data).then(
function(response) {
console.log(response); // undefined
this.transitionTo('orders'); // can't call on undefined
}
);
},
}
});
My issue was 'this' inside the function call was the wrong object. 我的问题是函数调用中的“ this”是错误的对象。 Solved by using var _this = this; 通过使用var _this = this解决;
I'll post the full working code.; 我将发布完整的工作代码。
import Ember from 'ember';
// Make 'session' available throughout the application
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
redirect: function () {
this.transitionTo('orders');
},
actions: {
authenticate: function () {
var data = {
identification: this.controller.get('identification'),
password: this.controller.get('password')
};
var _this = this;
this.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', data).then(
function(response) {
console.log(_this.get('session')); // this correctly gets the session
_this.transitionTo('orders');
}
);
},
}
});
The promise returned by the session's authenticate
method doesn't resolve with a value. 会话的authenticate
方法返回的promise不会使用值来解析。 You can access data that the authenticator resolves with via the session's secure
property, eg this.get('session.secure.token)'
. 您可以通过会话的secure
属性访问身份验证器解析的数据,例如this.get('session.secure.token)'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.