Ember 页面上未显示简单身份验证登录错误

Ember Simple Auth login errors not displaying on page

我正在观看设置 Ember 简单授权登录的在线视频教程。除了向模板显示登录错误(即 401 未授权)外,一切正常。我检查了代码是否有拼写错误,但找不到。

在控制器登录中,我尝试将 e.errors 记录到控制台,但控制台只显示 'Undefined'。但是,如果我只是将错误对象 e 发送到日志,那么我会得到其中包含 error.detail 的错误对象。注意:error.detail 是我试图在登录时显示的内容-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")}}

templates/components/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 收到的。 Simple Auth 中有一个重大变化。代码现在应该是 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
            });
        }
    }
});