Ember.js-如何将数据保存到身份验证器的会话中? [英] Ember.js - How can I save data to session from authenticator?
问题描述
我尝试做this.get('session'),但它什么也没给我.
I have tried doing this.get('session') but it gives me nothing.
我想将数据保存到我的会话中
I want to save data to my session
我似乎只从身份验证器那里获得了我需要的信息,但似乎无法传递它.(尝试了一些关于SO的建议方法,但似乎无法从验证者那里使用)
I only seem to get the information I need from the authenticator but can't seem to be able to pass it around. (Tried a couple of methods suggested on SO but none seem to be able to work from the autheticator)
import Ember from 'ember';
import Torii from 'ember-simple-auth/authenticators/torii';
const { service } = Ember.inject;
export default Torii.extend({
torii: service('torii'),
authenticate(options) {
return this._super(options).then(function (data) {
console.log(data);
});
}
});
身份验证者的呼叫者(我需要从这里访问的信息了吗?)
Caller of the autheticator (Is the info I need accessible from here already?)
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
authenticateSession() {
this.get('session').authenticate('authenticator:torii', 'google-token');
},
invalidateSession() {
this.get('session').invalidate();
}
}
});
推荐答案
您的身份验证器的 authenticate
方法无法解决任何问题.更改为
Your authenticator's authenticate
method does not resolve with anything. Change it to
import Ember from 'ember';
import Torii from 'ember-simple-auth/authenticators/torii';
const { service } = Ember.inject;
export default Torii.extend({
torii: service('torii'),
authenticate(options) {
return this._super(options).then(function (data) {
console.log(data);
return data;
});
}
});
通过会话的 data.authenticated
属性可以使用 data
中的所有属性,例如 this.get('session.data.authenticated.token')
.
to have all attributes in data
available via the session's data.authenticated
property, e.g. this.get('session.data.authenticated.token')
.
当然,在这种情况下,如果不需要日志记录,则可以完全删除覆盖的 authenticate
方法.
Of course in this case you can just remove the overridden authenticate
method completely if you don't need the logging.
这篇关于Ember.js-如何将数据保存到身份验证器的会话中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!