设置:
我用伪君子来模仿服务器。
泌尿酶:
使用自定义身份验证器与服务器进行接口。
有两个路由:登录,受保护(默认的索引,应用程序)
当我使用正确的凭据登录时,会调用身份验证器的身份验证方法,并成功地记录传递给解析()的响应对象。
意见:
AuthenticatedRouteMixin
)将返回登录页。ember_simple_auth:session -> {"authenticated":{}}
restore()
方法从未调用。
//authenticators/custom.js
import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';
export default Base.extend({
restore: function (data) {
return new Ember.RSVP.Promise(function (resolve, reject) {
console.log("RESOLVE",data);
if (!Ember.isEmpty(data.token)) {
//TODO Remove log
resolve(data);
} else {
console.log("REJECTING",data);
reject();
}
});
},
authenticate(credentials) {
return new Ember.RSVP.Promise((resolve, reject) =>
Ember.$.ajax({
url: '/token',
type: 'POST',
data: JSON.stringify({
email: credentials.identification,
password: credentials.password
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json'
}).then(function (response) {
Ember.run(function () {
//This logs the expected information
console.log("Response", response, response.token, response.user);
resolve(response);
});
}, function (xhr, status, error) {
console.log("error", error, xhr.responseText);
var response = xhr.responseText;
Ember.run(function () {
reject(response);
});
}));
},
invalidate(token) {
return API.logout(token);
}
});
//environment.js
ENV['ember-simple-auth'] = {
store: 'session-store:local-storage',
routeAfterAuthentication: '/protected'
};
TLDR;如何使会话持久?
发布于 2015-10-01 18:54:39
我终于让一切都在一起了。EMB2.0和ESA 1.0
以下是我所采取的步骤:
(这是导致问题中所描述的问题的最初问题)。
当ESA 1.0和Ember 2.0的Ember Cli发布后,所有这些都不应该成为一个问题:)
https://stackoverflow.com/questions/32862447
复制相似问题