简体   繁体   English

Ember Simple Auth Devise提供错误“无法读取未定义的属性'authenticate'” Rails 4后端

[英]Ember Simple Auth Devise giving error 'Cannot read property 'authenticate' of undefined' Rails 4 backend

I'm using Ember.SimpleAuth and the package for devise. 我正在使用Ember.SimpleAuth和用于设计的软件包。 I've used devise and rails numerous times before but I am pretty new to ember. 之前,我已经使用过很多次devise和rails了,但是我对炭烬还很陌生。 Also, I'm beginning to wonder if I should ditch devise for Ember apps with token authentication...Anyway here is my code. 另外,我开始怀疑我是否应该放弃使用令牌身份验证的Ember应用程序的设计……无论如何,这是我的代码。

UPDATE UPDATE

2 Specific things I noticed: 2我注意到的具体事项:

  1. I've cleaned up my assets and am using the latest ember-simple-auth.js. 我已经清理了我的资产,并且正在使用最新的ember-simple-auth.js。 I don't seem to have an authenticatorFactory because the following line is 'undefined' inside the 'var Session' definition: 我似乎没有AuthenticatorFactory,因为以下行在“ var Session”定义中是“ undefined”:

     _this.container.lookup(authenticatorFactory) 
  2. I feel like I should be calling the authenticate method that is in the ember-simple-auth-devise.js, but that file never gets touched according to my console. 我觉得我应该调用ember-simple-auth-devise.js中的authenticate方法,但是根据我的控制台,该文件永远不会被触摸。 Is that the way it should be? 那是应该的吗?

END UPDATE 结束更新


I'm pretty sure I followed the directions correctly: 我很确定我正确地遵循了指示:

application.js: 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
});

initializers/authentication.js.coffee 初始化/ authentication.js.coffee

Ember.Application.initializer
  name: "authentication"
  initialize: (container, application) ->
    Ember.SimpleAuth.setup container, application,
      authorizerFactory: 'ember-simple-auth-authorizer:devise'

I have a route defined for login: 我为登录定义了一条路由:

@route "login"

And a controller: 和一个控制器:

Quizzmob.LoginController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin,
    authenticatorFactory: "ember-simple-auth-authenticator:devise"
)

And my login form: 我的登录表单:

<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>

The error I get says: "TypeError: Cannot read property 'authenticate' of undefined" It is called on the authenticate method in ember-simple-auth.js, in the following location: 我得到的错误是:“ TypeError:无法读取未定义的属性'authenticate'”在ember-simple-auth.js中的以下位置的authenticate方法中调用它:

return new Ember.RSVP.Promise(function(resolve, reject) {
    _this.container.lookup(authenticatorFactory)|.authenticate(options).then(function(content) {
                                                ^

There is absolutely no request sent to the server, so I think there's something wrong with my ember setup. 绝对没有发送到服务器的请求,所以我认为我的余烬设置有问题。

I had this same error with Ember CLI, I added to the Brocfile.js this: 我在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');

Save and restart the server. 保存并重新启动服务器。

ember server

So, make sure you are including ember-simple-auth-devise.js and that you are restarting the server. 因此,请确保您包含ember-simple-auth-devise.js并重新启动服务器。

身份验证器注册为ember-simple-auth-authenticator:devise ,而不是ember-simple-auth-authenticators:devise (不带's')。

Create a login.js controller, ember g controller login and add the authenticate code there... 创建一个login.js控制器, ember g controller login并在其中添加身份验证代码...

/controller/login.js /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.

相关问题 用Rails进行简单身份验证设计用户名而不是电子邮件? - ember simple auth with rails devise username instead of email? 给出“无法读取未定义的属性'密码'”而不是处理错误 - Giving "Cannot read property 'password' of undefined" instead of handling the error 使用ember应用,rails api和ember-cli-simple-auth-devise插件访问经过身份验证的用户 - Access the authenticated user with ember app, rails api, and ember-cli-simple-auth-devise addon 灰烬简单身份验证+设计抛出405 - Ember Simple Auth + Devise throws 405 具有多个设计范围的Ember Simple Auth - Ember Simple Auth with Multiple Devise Scopes 余烬简单的身份验证回调问题 - ember simple auth authenticate callback issue 使用Django后端进行Ember简单Auth注销操作 - Ember Simple Auth Logout Action with Django Backend 无法运行护照登录策略。 身份验证错误~类型错误:无法读取未定义的属性“身份验证” - Trouble running passport login Strategy. Authentication error~ TypeError: Cannot read property 'authenticate' of undefined 使用Ember-Simple-Auth-Devise.js回调的Ember-Simple-Auth 3.1 - Ember-Simple-Auth 3.1 using Ember-Simple-Auth-Devise.js Callback firebase onAuth()抛出:TypeError无法读取未定义的属性'auth' - firebase onAuth() throwing: TypeError cannot read property 'auth' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM