Friday 30 December 2016

Should I create a jwt token when i POST to the /user?

So when I POST to /user I simply create a user object, hash the password etc.I was wondering if I should be creating a token at this time as well or should i leave it for /authentication as I have already.// create a new user account router.post('/user', function(req, res) { if (!req.body.username || !req.body.password || !req.body.email) { res.json({success: false, msg: 'Please enter a userame, password and an email.'}); } else { var newUser = new User({ username: req.body.username, password: req.body.password, email: req.body.email }); // save the user newUser.save(function(err) { if (err) { return res.json({success: false, msg: 'Username/email already exists.'}); } res.json({success: true, msg: 'Successful created new user.', user: {username: req.body.username, email: req.body.email} }); }); } });

Submitted December 30, 2016 at 10:21AM by farhansyed7911

No comments:

Post a Comment