Ember Simple Auth自定义验证器 [英] Ember Simple Auth custom authenticator

查看:82
本文介绍了Ember Simple Auth自定义验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建一个 session.currentUser 属性,一个 id 电子邮件属性。

I've been trying to create a session.currentUser property with an id, email, and points properties.

我引用具有Ember简单验证+ Ember CLI的自定义验证器如何将用户存储在会话中,但我只是不能我们正在使用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.

在我的 index.html 中,我有:

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'
};

initializers / 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);
  }
};

希望这有助于别人。

这篇关于Ember Simple Auth自定义验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆