Ember Simple Auth 自定义身份验证器 [英] Ember Simple Auth custom authenticator
问题描述
我一直在尝试使用 id
、email
和 points
创建一个 session.currentUser
属性> 属性.
I've been trying to create a session.currentUser
property with an id
, email
, and points
properties.
我参考了 自定义身份验证器与 Ember simple auth + Ember CLI 和 如何在会话中存储用户,但我就是不知道这些部分是如何组合在一起的.
I'm referencing Custom authenticator with Ember simple auth + Ember CLI and How to store the user in a session, but I just can't figure out how the pieces fit together.
我正在使用 Ember CLI.在我的 index.html
中,我有:
I'm using Ember CLI. In my index.html
, I have:
window.ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise',
session: 'session:custom'
};
在 initializers/custom-session.js
中,我有:
import Session from 'simple-auth/session';
import Devise from 'simple-auth-devise/authenticators/devise';
export default {
name: 'session:custom',
before: 'simple-auth',
initialize: function(container) {
container.register('session:custom', Devise);
Session.extend({
currentUser: function() {
var id = this.get('id');
var email: this.get('user_email');
var points: this.get('points');
if (!Ember.isEmpty(id)) {
return this.store.createRecord('user', {
id: id,
email: email,
points: points
});
}
}.property('id')
});
}
};
我觉得这在很多方面都是错误的,但经过几个小时的努力,这至少表明了我正在努力实现的目标.
This feels wrong to me in many ways, but after several hours of trying to make this work, it's at least an indication of what I'm trying to accomplish.
如果能得到任何帮助,我将不胜感激.提前谢谢你!
I'd be super grateful for any help. Thank you in advance!
推荐答案
我明白了!!!:)
index.html:
index.html:
window.ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise',
session: 'session:withCurrentUser'
};
初始化程序/customize-session.js:
initializers/customize-session.js:
import Session from 'simple-auth/session';
var SessionWithCurrentUser = Session.extend({
currentUser: function() {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return this.container.lookup('store:main').find('user', userId);
}
}.property('user_id')
});
export default {
name: 'customize-session',
initialize: function(container) {
container.register('session:withCurrentUser', SessionWithCurrentUser);
}
};
希望这对其他人有帮助.
Hope this helps someone else.
这篇关于Ember Simple Auth 自定义身份验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!