Ember Simple Auth custom authenticator

后端 未结 1 674
既然无缘
既然无缘 2021-01-14 16:12

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

I\'m referen

1条回答
  •  执念已碎
    2021-01-14 16:42

    I got it!!! :)

    index.html:

    window.ENV['simple-auth'] = {
      authorizer: 'simple-auth-authorizer:devise',
      session: 'session:withCurrentUser'
    };
    

    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.

    0 讨论(0)
提交回复
热议问题