server/controllers/AuthController.js
/**
 *
 * POST /auth/signup
 * Route for signing up new users
 */
POST /auth/signup
Route for signing up new users
POST / auth / signup Route for signing up new users
static async userSignUp(req, res) {
    const { error } = Validate.userSignup(req.body);
    if (error) return res.status(400).send({ status: 400, error: error.details[0].message });
    const {
      username, firstname, lastname, password,
    } = req.body;
    const email = username;
    let user = await db.query(
      'SELECT * FROM users WHERE email = ($1)', [email],
    );
    if (user.rowCount !== 0) return res.status(400).send({ status: 400, error: "user already exists" });
    const hashpassword = await bcrypt.hash(password, 10);
    user = await db.query(
      `INSERT INTO "users" ("firstname", "lastname", "email", "password")
      VALUES ('${firstname}','${lastname}', '${email}', '${hashpassword}') RETURNING *`,
    );
    const token = jwt.sign({
      _id: user.rows[0].id,
      _email: user.rows[0].email,
    }, process.env.jwtPrivateKey);
    res.header('x-auth-token', token).send({ status: 200, data: [{ token }] });
  }
static async userSignUp ( req , res ) { const { error } = Validate . userSignup ( req . body ) ; if ( error ) return res . status ( 400 ) . send ( { status : 400 , error : error . details [ 0 ] . message } ) ; const { username , firstname , lastname , password , } = req . body ; const email = username ; let user = await db . query ( 'SELECT * FROM users WHERE email = ($1)' , [ email ] , ) ; if ( user . rowCount !== 0 ) return res . status ( 400 ) . send ( { status : 400 , error : "user already exists" } ) ; const hashpassword = await bcrypt . hash ( password , 10 ) ; user = await db . query ( ` ${ firstname } ${ lastname } ${ email } ${ hashpassword } ` , ) ; const token = jwt . sign ( { _id : user . rows [ 0 ] . id , _email : user . rows [ 0 ] . email , } , process . env . jwtPrivateKey ) ; res . header ( 'x-auth-token' , token ) . send ( { status : 200 , data : [ { token } ] } ) ; }
POST /auth/signup
 Route for signing up new users
POST / auth / signup Route for signing up new users
// console.log(user); // await db.end();