Reputation: 2997
I've been trying to create a session.currentUser
property with an id
, email
, and points
properties.
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.
I'm using Ember CLI. In my 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 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!
Upvotes: 3
Views: 1161
Reputation: 2997
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.
Upvotes: 3