2015-09-12 89 views
2

我下面這個教程在這裏:SailsJS用戶創建不返回

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

我遇到了一個問題,在User.create(...);行代碼不返回,因此我的郵差測試時間出。

的代碼,我想在這裏引起該問題的塊是:

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... 

但我沒有看到第二個控制檯輸出=/

任何人都知道我做錯了什麼?

回答

0

好的,我的壞...好像我錯過了上述教程時的一行。

我在User.js模型類有這樣的:

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

當它應該是:

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

    next(); // <--- this line was missing 

}