Sails.js Waterlock / auth / register raises a 500 error

When trying to force Waterlock not to create a new user when logging in.

When I install createOnNotFoundin falseand try to use a http://localhost:1337/auth/register?email=a@s.d&password=12345678new user to register. I have a 500 error :

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]

The register module , where an error occurs, is part of the waterlock .

Here the registration module code is the same as now:

'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

How can I register a user now?

UPDATE:

This is due to a register action not yet implemented in waterlock-local-auth , which I use for authentication. See this PR for more details .

, :, , ?

+4
1

/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);
                });
        });
    }

});

, .

Wayne-o, Waterlock, waterlock-local-auth.

+3

All Articles