代码之家  ›  专栏  ›  技术社区  ›  J Weezy

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

  •  1
  • J Weezy  · 技术社区  · 7 年前

    在控制器登录中,我尝试记录 e.errors 到控制台,但控制台只是说'未定义'。不过,如果我只是发送错误对象 e error.detail 在里面。注:以下为 错误。详细信息 是我试图在login-form.hsb上显示的内容。

    感谢您的帮助!

    • 余烬数据:3.4.2
    • 灰烬简单认证:1.7.0

    控制器/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-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>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Eric Aya    7 年前

    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
                });
            }
        }
    });
    
    推荐文章