[英]Ember Simple Auth login errors not displaying on page
我正在關注一個在線視頻教程,該教程設置了Ember Simple Auth Login。 一切正常,但向模板顯示登錄錯誤(即未經授權的401)。 我已經檢查了輸入錯誤的代碼,但找不到任何錯誤。
在控制器登錄中,我嘗試將e.errors
記錄到控制台,但控制台僅顯示“未定義”。 但是,如果我只是將錯誤對象e
到日志, error.detail
在其中包含error.detail
的錯誤對象。 注意: error.detail
是我試圖在login-form.hsb上顯示的內容。
任何幫助表示贊賞!
控制器/login.js
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
export default Controller.extend({
session: service('session'),
actions: {
login(attrs) {
this.get('session').authenticate('authenticator:jwt', {
email: attrs.email,
password: attrs.password
}).then(() => {
this.transitionToRoute('index');
}).catch((e) => {
this.set('errors', e.errors); // nothing is being displayed
console.log(e.errors); // Says Undefined in the console
console.log(e); // Display error to console
});
}
}
});
模板/login.hsb
{{login-form user=model errors=errors onsubmit=(action "login")}}
模板/組件/login-form.hbs
<div class="slide-out">
<div class="slide-out-card">
<div class="slide-out-heading">
<div class="title">
<h3>Login</h3>
</div>
</div>
<div class="slide-out-content">
<form onsubmit={{action "login"}}>
<!-- this does not display the error message -->
{{#each errors as |error|}}
{{error.detail}}
<div class="error-alert">{{error.detail}}</div>
{{/each}}
<div class="field">
<label>Email:</label>
{{input type="text" placeholder="Email" value=email}}
</div>
<div class="field">
<label>Password:</label>
{{input type="password" placeholder="Password" value=password}}
</div>
<div class="form-footer">
<button type="submit" class="btn-submit">save</button>
</div>
</form>
</div>
</div>
</div>
答案是從Embercasts收到的。 簡單身份驗證有一個重大變化。 該代碼現在應該是e.json.errors
export default Controller.extend({
session: service('session'),
actions: {
login(attrs) {
this.get('session').authenticate('authenticator:jwt', {
email: attrs.email,
password: attrs.password
}).then(() => {
this.transitionToRoute('index');
}).catch((e) => {
this.set('errors', e.json.errors); // Breaking change to Simple Auth - should be e.json.errors, instead of e.errors
});
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.