Ember.js 无法读取属性';规范化&x27;未定义的

Ember.js 无法读取属性';规范化&x27;未定义的,ember.js,ember-data,Ember.js,Ember Data,我是新来的灰烬。我目前使用的是Ember 1.5和Ember Data 1.0.0-beta.7+canary.b45e23ba以及Ember simple auth 0.2.1 我正在努力解决这样一个场景:我想对一个API进行两次自定义调用以进行登录。以下是我的代码: App.ApplicationAdapter = DS.RESTAdapter.reopen host: '//localhost:8443' namespace: 'api/v1' App.store = D

我是新来的灰烬。我目前使用的是Ember 1.5和Ember Data 1.0.0-beta.7+canary.b45e23ba以及Ember simple auth 0.2.1

我正在努力解决这样一个场景:我想对一个API进行两次自定义调用以进行登录。以下是我的代码:

App.ApplicationAdapter = DS.RESTAdapter.reopen
    host: '//localhost:8443'
    namespace: 'api/v1'

App.store = DS.Store.create
    adapter: App.ApplicationAdapter

App.User = DS.Model.extend()

Ember.Application.initializer
    name: 'authentication'
    initialize: (container, application) ->
        container.register('authenticators:custom', App.Authenticator);
        Ember.SimpleAuth.setup(container, application)


App.Authenticator = Ember.SimpleAuth.Authenticators.OAuth2.extend
    authenticate: (credentials) ->
        return new Ember.RSVP.Promise (resolve, reject) ->
            Ember.$.ajax
                url:  '//localhost:8443/api/v1/login'
                type: 'POST'
                data: { email: credentials.identification, password: credentials.password }
            .then (response) ->
                token = response.token
                userId = response.userId

                # Add authorization header
                App.ApplicationAdapter.reopen
                    headers: 
                        Authorization: 'Bearer '+response.access_token

                # Load the user data
                App.store
                .find('user', response.userId)
                .then (response) ->
                    Ember.run ->
                        resolve({ access_token: token, account_id: userId })
                , (xhr, status, error) ->
                    Ember.run ->
                        reject(xhr.responseText)

            , (xhr, status, error) ->
                Ember.run ->
                    reject(xhr.responseText)
1/上述代码到达
App.store.find('user',response.userId)
时将失败。投掷:

Uncaught TypeError: Cannot read property 'normalize' of undefined ember-data.js:9806
Ember.Object.extend.modelFor ember-data.js:9806
Ember.Object.extend.findById ember-data.js:9098
Ember.Object.extend.find ember-data.js:9085
(anonymous function) initializers.coffee:30
(anonymous function) jquery.js:3206
fire jquery.js:3049
self.fireWith jquery.js:3161
done jquery.js:8185
(anonymous function) jquery.js:8532
2/我对使用Ember Data 1.0的RestaAdapter获得商店所需的内容有点困惑。显然,API发生了变化,我不知道我的
App.store
是否是实例化商店的正确方法


谢谢你的帮助

用以下内容替换您的查找结果:

container.lookup('store:main').find('user', response.userId)

不确定Ember数据的内容,但您不需要手动将承载令牌头添加到适配器-Ember.SimpleAuth会自动执行此操作。没有身份验证程序的情况下,会出现此问题。哦,你找到解决办法了吗?不幸的是没有。我给余烬一个旋转的乐趣,并没有深入挖掘这一点。