Ember Simple Auth Virtual Authenticator
I am trying to create a property session.currentUser
with properties id
, email
and points
.
I am referring to Custom Authenticator with Ember simple auth + Ember CLI and How to keep user in session , but I just can't figure out how the shapes fit together.
I am using Ember CLI. In mine index.html
I have:
window.ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise',
session: 'session:custom'
};
In initializers/custom-session.js
I have:
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 seems wrong to me in many ways, but after hours of trying to make this work, it at least indicates what I am trying to accomplish.
I would be very grateful for any help. Thank you in advance!
source to share
I understood!:)
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.
source to share