【发布时间】:2018-03-28 00:43:33
【问题描述】:
我正在使用带有基于 Cookie 的身份验证的 ember-simple-auth。 当我登录时 {{session.isAuthenticated}} 是真的,但是当我重新加载页面时这是假的,但是 localStore 没有改变。
这是我的 custom.js 身份验证器:
import Base from 'ember-simple-auth/authenticators/base';
import config from '../config/environment';
export default Base.extend({
tokenEndpoint: config.apiUrl + '/user/signIn',
restore(data) {
console.log(data);
return RSVP.resolve(data);
},
authenticate(username, password) {
return Ember.$.ajax({
url: this.tokenEndpoint,
type: 'POST',
data: JSON.stringify({
username: username,
password: password,
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json',
});
},
invalidate: function () {
return Ember.RSVP.resolve();
},
});
我在 application.hbs 中使用 {{session.isAuthenticated}}。所以我在应用程序控制器中注入会话:
session: Ember.inject.service('session')
【问题讨论】:
-
这是我在 localStorage 中所拥有的: ember_simple_auth-session : "{"authenticated":{"authenticator":"authenticator:custom","item":{"username":"admin@a .com"}}}"
标签: ember.js ember-simple-auth