Sails.js Waterlock /auth/register causes error 500

蓝咒 提交于 2019-12-05 16:26:01

I've solved this with 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 already exists");
            else
                waterlock.engine.findOrCreateAuth(criteria, attr, function(err, user) {
                    if (err)
                        return res.badRequest(err);
                    delete user.password;
                    return res.ok(user);
                });
        });
    }

});

This is exactely what I need.

Meanwhile Wayne-o, one of Waterlock contributors, said that he will finish his implementation of registration in waterlock-local-auth.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!