Skip to content
Snippets Groups Projects
Commit 39ff8c06 authored by V S Tharunika's avatar V S Tharunika
Browse files

added token to register function

parent 2f047a37
Branches
No related tags found
No related merge requests found
...@@ -14,13 +14,16 @@ module.exports={ ...@@ -14,13 +14,16 @@ module.exports={
try{ try{
const user= await User.create(req.body) const user= await User.create(req.body)
res.send(user.toJSON()) const userJson = user.toJSON()
res.send({
user: userJSON,
token: jwtSignUser(userJson)
})
} catch (err){ } catch (err){
res.status(400).send({ res.status(400).send({
error: 'This email account is already in use.' error: 'This email account is already in use.'
}) })
} }
}, },
async login(req, res) { async login(req, res) {
try{ try{
......
const Promise = require('bluebird') const Promise = require('bluebird')
const bcrypt = Promise.promisifiyAll(require('bcrypt-nodejs')) const bcrypt = Promise.promisifyAll(require('bcrypt-nodejs'))
function hashPassword (user, options) { function hashPassword (user, options) {
const SALT_FACTOR = 8 const SALT_FACTOR = 8
...@@ -17,7 +17,7 @@ function hashPassword (user, options) { ...@@ -17,7 +17,7 @@ function hashPassword (user, options) {
} }
module.exports = (sequelize, DataTypes) => { module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('user',{ const User = sequelize.define('User', {
email: { email: {
type: DataTypes.STRING, type: DataTypes.STRING,
unique: true unique: true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment