問題: コントローラーで現在のセッションを取得する方法がわかりません。
次のように定義されたカスタム認証子、カスタム セッション、および初期化子があります。
../app/authenticators/custom.js のカスタム認証者
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);
});
});
}
});
../app/sessions/custom.js のカスタム セッション
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;
../app/initializers/authentication.js の 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);
}
};
を使用してコントローラーの 1 つでtoken
andを取得しようとしていますが、次の結果が得られます。userData
this.get('session')
Class {store: Class, __ember1420041799205: "ember297", __nextSuper: undefined, __ember_meta__: Object, constructor: function…}
ember_simple_auth:session
ローカル ブラウザ ストレージにキーと値が表示されます{"authenticator":"authenticator:custom","token":"123456789","userData":{"id":"1","email":"something@email.com","api_key":"123456789","expiry_time":"2014-12-31 14:02:56"}}
基本的に、ローカル ストレージにあるものを取得する必要があります。どうすればいいですか?