【问题标题】:SailsJS User create doesn't returnSailsJS 用户创建不返回
【发布时间】:2015-09-12 07:50:30
【问题描述】:

我在这里学习本教程:

https://ericswann.wordpress.com/2015/04/24/nozus-js-1-intro-to-sails-with-passport-and-jwt-json-web-token-auth/

我遇到了User.create(...); 代码行没有返回的问题,因此我的 POSTMAN 测试超时。

我认为导致问题的代码块是:

signup: function(req, res) {
    console.log('\n\nCreating a new user...');

    User
    .create(_.omit(req.allParams(), 'id'))
    .then(function (user) {
        console.log('\n\nreturning newly created user...');

        return {
            // TODO: replace with new type of cipher service
            token: CipherService.createToken(user),
            user: user
        };
    })
    .then(res.created)
    .catch(res.serverError);
},

我看到了第一个控制台输出:

info: Starting app...

info: 
info:                .-..-.
info: 
info:    Sails              <|    .-..-.
info:    v0.11.0             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------' 
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `/Users/MacUser/SailsProjects/myApi`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Sat Sep 12 2015 15:41:21 GMT+0800 (AWST)

debug: Environment : development
debug: Port        : 1337
debug: --------------------------------------------------------


Creating a new user...

但我没有看到第二个控制台输出 =/

有人知道我做错了什么吗?

【问题讨论】:

    标签: sails.js jwt


    【解决方案1】:

    好吧,我的错……好像我在遵循上述教程时漏掉了一行。

    我的 User.js 模型类中有这个:

    beforeCreate: function(values, next) {
        CipherService.hashPassword(values);
    }
    

    什么时候应该:

    beforeCreate: function(values, next) {
        CipherService.hashPassword(values);
    
        next(); // <--- this line was missing
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 2017-06-25
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多