Sails.js Waterlock / auth / register导致错误500

在试图使Waterlock不能在login时创build新用户。

当我将createOnNotFound设置为false并尝试使用http://localhost:1337/auth/register?email=a@sd&password=12345678注册新用户时。 我有500个错误:

 error: Sending 500 ("Server Error") response: TypeError: undefined is not a function at Object.module.exports (D:\temp\sails-waterlock\node_modules\waterlock\lib\controllers\actions\register.js:25:44) at bound (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) at routeTargetFnWrapper (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) at pass (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11) at C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:187:7 at alwaysAllow (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11) at routeTargetFnWrapper (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) at pass (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) [TypeError: undefined is not a function] 

发生错误的寄存器模块是锁库的一部分。

这里是注册模块的代码,因为它现在是:

 'use strict'; /** * login action * * tries to find if we have an auth method to handle this type of login * request. * * GET /auth/login */ module.exports = function(req, res){ var params = waterlock._utils.allParams(req); // If there is only 1 chosen auth method just assume it if(waterlock._utils.countTopLevel(waterlock.methods) === 1){ params.type = waterlock._utils.accessObjectLikeArray(0, waterlock.methods).authType; } if(typeof params.type === 'undefined'){ return res.badRequest('You must specify a type parameter.'); } if(waterlock.methods.hasOwnProperty(params.type)){ // call the login function of the correct auth type waterlock.methods[params.type].actions.register(req, res); }else{ return res.badRequest('unknown/invalid authentication type'); } }; 

Sails v 0.11,Waterlock v 0.1.0

我现在如何注册用户?

更新:

发生这种情况是由于注册操作尚未在我用于身份validation的waterlock-local-auth模块中实现。 详情请看这个PR 。

所以更新的问题是:如何工作,直到执行完成?

       

网上收集的解决方案 "Sails.js Waterlock / auth / register导致错误500"

我用/controllers/AuthController.js自定义注册动作解决了这个问题:

 module.exports = require('waterlock').waterlocked({ register: function(req, res) { var params = req.params.all(), def = waterlock.Auth.definition, criteria = { }, scopeKey = def.email !== undefined ? 'email' : 'username'; var attr = { password: params.password } attr[scopeKey] = params[scopeKey]; criteria[scopeKey] = attr[scopeKey]; waterlock.engine.findAuth(criteria, function(err, user) { if (user) return res.badRequest("User already exists"); else waterlock.engine.findOrCreateAuth(criteria, attr, function(err, user) { if (err) return res.badRequest(err); delete user.password; return res.ok(user); }); }); } }); 

这是我所需要的。

与此同时,Waterlock的投稿人之一Wayne-o 说 ,他将完成他在本地 注册的注册 。