2014-06-20 2 views
3

this example in the docs과 비슷한 사용자 정의 인증 기 작성을 시도하고 있습니다. 목표는 session.user을 통해 현재 로그인 한 사용자를 검색 할 수있게하는 것입니다. 내가 인증 할 때 나는Ember simple auth + Ember CLI가있는 사용자 정의 인증 자

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' 
    }); 
    } 
}; 

initializers/authentication.js에 있도록

나는, 엠버 CLI를 사용하고 내가받을 다음과 같은 오류 : 왜

TypeError: Cannot read property 'authenticate' of undefined 
at __exports__.default.Ember.ObjectProxy.extend.authenticate 

어떤 생각?

답변

0

문제는 AMD 빌드가 현재 확장 라이브러리의 구성 요소를 자동으로 등록하지 않는다는 것입니다 (https://github.com/simplabs/ember-simple-auth/issues/198 참조). 나는 다음 버전에서 그것을 바꿀 것이며 아마도 브라우저 화 된 버전 대신에 AMD 빌드에보다 집중할 수 있도록 문서를 채택 할 것입니다.

Em.SimpleAuth.Authenticators.OAuth2.reopen 
    serverTokenEndpoint: "http://myapp.com/token" 
    authenticate: (credentials) -> 
     new Em.RSVP.Promise (resolve, reject) => 
     data = 
      grant_type: "password" 
      username: credentials.identification 
      password: credentials.password 

     @makeRequest(data).then (response) => 
      # success call 
     , (xhr, status, error) -> 
      # fail call 

내가 일이 될 수 있다고 생각하는 것은 당신이 인증과 등록되어 있습니다 : 순간을 위해 당신은

container.register(
    'ember-simple-auth-authorizer:devise', 
    Ember.SimpleAuth.Authorizers.Devise 
); 
container.register(
    'ember-simple-auth-authenticator:devise', 
    Ember.SimpleAuth.Authenticators.Devise 
); 
+0

내가 추가 간단한 인증 0.6.4의로 –

+0

'Ember.SimpleAuth.setup'을 호출하기 전에 * 행을 삽입 했습니까? – marcoow

+0

나는 더 이상 사용자 정의 인증자를 필요로하지 않았지만 나는 그러했다. –

1

당신은 같은 것을 할 필요가 귀하의 이니셜이 실행해야 할 것 응용 프로그램이 아니라 인증 자 자체?

index.html을 :

window.ENV['simple-auth'] = { 
    authorizer: 'simple-auth-authorizer:devise', 
    session: 'session:withCurrentUser' 
}; 

초기화/사용자 정의 - session.js :

import Ember from 'ember'; 
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); 
    } 
}; 
+0

포함 된 인증자를 다시 여는 것처럼 보이지만,'.extend'가 아니라'.reopen '이 아니라는 것을 의미합니다. 단기적인 해결책입니다. 감사! –

5

, 당신은 지금 무엇인가 할 수있다 이 라인들은 여전히 ​​작동하지 않습니다
+0

이것은 ember-cli 및 simple-auth의 최신 버전에서 수행하는 방법입니다. 그러나'ENV'를'MyAppENV'에 바인드하는 것이 더 낫습니다. 그래서, index.html :'window.ENV = window.MyAppENV;'(참조 : http://stackoverflow.com/a/24845613/2637573). environt.js에서 다음을 ENV에 추가합니다.''simple-auth ': {authorizer :'간단한 인증 기관 : devise ', 세션 :'session : withCurrentUser '}' – AWM

+0

ember-cli 0.0.46 및 simple- auth 0.6.7 당신은'window.ENV = window.MyAppENV;'또는'index.html'에있는 다른 것을 더 이상 포함 할 필요가 없습니다. – AWM