node.js - Sails.js Waterlock /auth/register causes error 500 -
in trying make waterlock not create new user on login.
when set createonnotfound
false
, try use http://localhost:1337/auth/register?email=a@s.d&password=12345678
register new user. i've got 500 error:
error: sending 500 ("server error") response: typeerror: undefined not function @ object.module.exports (d:\temp\sails-waterlock\node_modules\waterlock\lib\controllers\actions\register.js:25:44) @ bound (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) @ routetargetfnwrapper (c:\users\sandres\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) @ callbacks (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) @ param (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) @ param (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) @ pass (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) @ nextroute (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7) @ callbacks (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11) @ c:\users\sandres\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:187:7 @ alwaysallow (c:\users\sandres\appdata\roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11) @ routetargetfnwrapper (c:\users\sandres\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) @ callbacks (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) @ param (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) @ param (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) @ pass (c:\users\sandres\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) [typeerror: undefined not function]
the register module, error happens part of waterlock library.
here goes code of register module now:
'use strict'; /** * login action * * tries find if have auth method handle type of login * request. * * /auth/login */ module.exports = function(req, res){ var params = waterlock._utils.allparams(req); // if there 1 chosen auth method assume 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 type parameter.'); } if(waterlock.methods.hasownproperty(params.type)){ // call login function of 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
how can register user now?
update:
this happens due register action not yet implemented in waterlock-local-auth module use authentication. see this pr details.
so updated question is: how work around until implementation done?
i've solved custom registration action in /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 exists"); else waterlock.engine.findorcreateauth(criteria, attr, function(err, user) { if (err) return res.badrequest(err); delete user.password; return res.ok(user); }); }); } });
this exactely need.
meanwhile wayne-o, 1 of waterlock contributors, said finish implementation of registration in waterlock-local-auth.
Comments
Post a Comment