cphill cphill - 6 months ago 72
Javascript Question

JavaScript Invoking String

I am running into a string violation error with my ORM that is related to the value being passed to the authenticationToken property in my method. Is this due to the fact that I'm returning the method? The value I am looking to pass is

buf.toString('hex')
.

.post(function(req, res, organization){

function token() {
return crypto.randomBytes(20, function(err, buf){
buf.toString('hex');
});
};

models.Member.create({
organizationId: req.body.organizationId,
memberEmail: req.body.addMember,
}).then(function(){

return models.User.create({
email: req.body.addMember,
authenticationToken: token()
});
}).then(function(){
console.log("Success");
res.redirect('/app/settings/add-users');
})
});


Here is my error:

Unhandled rejection SequelizeValidationError: string violation: authenticationToken cannot be an array or an object

Answer

Could be a missing return keyword? The anonymous function in your call to crypto.randomBytes doesn't return anything.