我正在关注一个在线视频教程,该教程设置了Ember Simple Auth Login。一切正常,但会向模板显示登录错误(即未经授权的401)。我已经检查了代码中是否有错别字,但找不到。
在控制器登录中,我尝试将e.errors
登录到控制台,但控制台仅显示'Undefined'。但是,如果我只是将错误对象e
发送到日志,则会得到其中包含error.detail
的错误对象。注意:error.detail
是我要在login-form.hsb上显示的内容。
感谢您的帮助!
Controllers / 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
});
}
}
});
templates / login.hsb
{{login-form user=model errors=errors onsubmit=(action "login")}}
模板/组件/登录表单.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>
答案 0 :(得分:0)
答案是从Embercasts收到的。简单身份验证有一个重大变化。现在,代码应为CASE END (ANSI SQL)
e.json.errors