Ember CLI - 简单身份验证 - 自定义身份验证器不会自动注册

时间:2014-12-02 18:49:23

标签: ember.js ember-cli ember-simple-auth

我正在尝试使用ember simple auth设置自定义身份验证器。我使用的是Ember CLI,根据GitHub上的Simple Auth ReadMe,它说明了这一点。 请注意,当您不使用Ember CLI时,验证程序将不会自动注册容器,您需要在初始化程序中执行此操作。

它没有说明您需要在您的目录结构中放置验证器(或授权者)的位置,以便Ember CLI自动注册它。在 app / authenticators / custom.js 中创建我的文件后(如我所读的示例所示),我希望它可以在容器中注册。看着Ember Inspector,它无处可寻。

有没有人对此有任何见解?这些文件放在哪里?

请询问是否需要任何其他信息。

Ember: 1.7.0
Ember Data: 1.0.0-beta.10
Ember Simple Auth: 0.7.1

3 个答案:

答案 0 :(得分:1)

最新版本的Ember CLI实际上应该自动注册验证器 - 确保你正在使用它(你可能不是因为你仍然在Ember 1.7.0)。那应该解决它。

答案 1 :(得分:0)

确保您的初始值设定项位于/app/initializers/。此目录中的初始化程序由ember-cli自动设置。

// app/initializers/authentication.js
import CustomAuthenticator from '../authenticators/custom';

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

答案 2 :(得分:0)

我遇到了同样的问题,我有Ember 1.8.1

错误是: Uncaught ReferenceError: CustomAuthenticator is not defined 在文件app / authenticators / custom.js

我需要添加一个初始化程序并将文档中的代码更改为以下内容,并且可以正常工作

import Base from 'simple-auth/authenticators/base';

var CustomAuthenticator = Base.extend({
  restore: function(data) {
  },
  authenticate: function(options) {
  },
  invalidate: function(data) {
  }
});

export default CustomAuthenticator;
相关问题