mercredi 31 décembre 2014

How do I get attributes of Custom Session using Ember Simple Auth

PROBLEM: I don't know how to get the current session in a controller.


I have a custom authenticator, custom session, and initializer defined like so:


CUSTOM AUTHENTICATOR



var CustomAuthenticator = Base.extend({
authenticate: function(credentials) {
return new Ember.RSVP.Promise(function (resolve, reject){
var loginPromise = Ember.$.post('/api/login', {'email':credentials.identification, 'password':credentials.password} );
loginPromise.then(function (data){
resolve({
token: data.user.api_key,
userData: data.user
});
}, function(error){
reject(error);
});
});
}
});


CUSTOM SESSION



import Ember from 'ember';
import Session from 'simple-auth/session';

var CustomSession = Session.extend({
after:'simple-auth',
currentUser: function(){
return this.container.lookup('ember_simple_auth:session');
}.property('currentUser')
});

export default CustomSession;


INITIALIZER



import CustomAuthenticator from '../authenticators/custom';
import CustomSession from '../sessions/custom';

export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container) {
container.register('authenticator:custom', CustomAuthenticator);
container.register('session:custom', CustomSession);
}
};


I'm trying to get the token and userData in one of my controllers by using this.get('session') but it's giving me the following:



Class {store: Class, __ember1420041799205: "ember297", __nextSuper: undefined, __ember_meta__: Object, constructor: function…}


and I see the ember_simple_auth:session key and values in the local browser storage {"authenticator":"authenticator:custom","token":"123456789","userData":{"id":"1","email":"something@email.com","api_key":"123456789","expiry_time":"2014-12-31 14:02:56"}}


I basically need to get what's in the local storage. How do I do this?





Aucun commentaire:

Enregistrer un commentaire