我想寫一個自定義身份驗證器,類似於從this example in the docs。目標是能夠通過session.user
檢索當前登錄的用戶。自定義身份驗證與Ember簡單身份驗證+ Ember CLI
我用灰燼CLI,所以在initializers/authentication.js
我
import Ember from 'ember';
var customAuthenticator = Ember.SimpleAuth.Authenticators.Devise.extend({
authenticate: function(credentials) {
debugger;
}
});
export default {
name: 'authentication',
initialize: function(container, application) {
Ember.SimpleAuth.Session.reopen({
user: function() {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return container.lookup('store:main').find('user', userId);
}
}.property('userId')
});
// register the custom authenticator so the session can find it
container.register('authenticator:custom', customAuthenticator);
Ember.SimpleAuth.setup(container, application, {
routeAfterAuthentication: 'landing-pages',
authorizerFactory: 'ember-simple-auth-authorizer:devise'
});
}
};
當我嘗試驗證,我得到以下錯誤:
TypeError: Cannot read property 'authenticate' of undefined
at __exports__.default.Ember.ObjectProxy.extend.authenticate
任何想法,爲什麼?
我加這些行,但它仍然不能正常工作 –
在調用'Ember.SimpleAuth.setup'之前你插入了行*嗎? – marcoow
我做到了,儘管我不再需要自定義身份驗證器。 –