[英]Ember Simple Auth Devise giving error 'Cannot read property 'authenticate' of undefined' Rails 4 backend
我正在使用Ember.SimpleAuth和用于设计的软件包。 之前,我已经使用过很多次devise和rails了,但是我对炭烬还很陌生。 另外,我开始怀疑我是否应该放弃使用令牌身份验证的Ember应用程序的设计……无论如何,这是我的代码。
UPDATE
2我注意到的具体事项:
我已经清理了我的资产,并且正在使用最新的ember-simple-auth.js。 我似乎没有AuthenticatorFactory,因为以下行在“ var Session”定义中是“ undefined”:
_this.container.lookup(authenticatorFactory)
我觉得我应该调用ember-simple-auth-devise.js中的authenticate方法,但是根据我的控制台,该文件永远不会被触摸。 那是应该的吗?
结束更新
我很确定我正确地遵循了指示:
application.js中:
//= require jquery
//= require jquery_ujs
//= require handlebars
//= require ember
//= require ember-data
//= require quiz
//= require pen
//= require ember-simple-auth
//= require ember-simple-auth-devise
//= require_self
//= require quizzmob
Quizzmob = Ember.Application.create({
LOG_TRANSITIONS: true
});
初始化/ authentication.js.coffee
Ember.Application.initializer
name: "authentication"
initialize: (container, application) ->
Ember.SimpleAuth.setup container, application,
authorizerFactory: 'ember-simple-auth-authorizer:devise'
我为登录定义了一条路由:
@route "login"
和一个控制器:
Quizzmob.LoginController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin,
authenticatorFactory: "ember-simple-auth-authenticator:devise"
)
我的登录表单:
<form {{action 'authenticate' on='submit'}}>
<label for="identification">Login</label>
{{input id='identification' placeholder='Enter Login' value=identification}}
<label for="password">Password</label>
{{input id='password' placeholder='Enter Password' type='password' value=password}}
<button type="submit">Login</button>
</form>
我得到的错误是:“ TypeError:无法读取未定义的属性'authenticate'”在ember-simple-auth.js中的以下位置的authenticate方法中调用它:
return new Ember.RSVP.Promise(function(resolve, reject) {
_this.container.lookup(authenticatorFactory)|.authenticate(options).then(function(content) {
^
绝对没有发送到服务器的请求,所以我认为我的余烬设置有问题。
我在Ember CLI中也遇到了同样的错误,我在Brocfile.js中添加了以下内容:
app.import('vendor/ember-simple-auth/ember-simple-auth.js');
app.import('vendor/ember-simple-auth/ember-simple-auth-devise.js');
保存并重新启动服务器。
ember server
因此,请确保您包含ember-simple-auth-devise.js
并重新启动服务器。
身份验证器注册为ember-simple-auth-authenticator:devise
,而不是ember-simple-auth-authenticators:devise
(不带's')。
创建一个login.js
控制器, ember g controller login
并在其中添加身份验证代码...
/controller/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:devise'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.