[英]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.