server/controllers/AuthController.js
/**
 *
 * POST /auth/login
 * Route for login users
 */
POST /auth/login
Route for login users
POST / auth / login Route for login users
static async userLogin(req, res) {
    const { error } = Validate.userLogin(req.body);
    if (error) return res.status(400).send({ status: 400, error: error.details[0].message });
    const { email, password } = req.body;
    const user = await db.query(
      'SELECT * FROM users WHERE email = ($1)', [email],
    );
    if (user.rowCount !== 1) return res.status(400).send('Invalid email or password');
    const validPassword = await bcrypt.compare(password, user.rows[0].password);
    if (!validPassword) return res.status(400).send({ status: 400, error: "invalid email or password" });
    const token = jwt.sign({
      _id: user.rows[0].id,
      _email: user.rows[0].email,
    }, process.env.jwtPrivateKey);
    res.send({ status: 200, data: [{ token }] });
  }
static async userLogin ( req , res ) { const { error } = Validate . userLogin ( req . body ) ; if ( error ) return res . status ( 400 ) . send ( { status : 400 , error : error . details [ 0 ] . message } ) ; const { email , password } = req . body ; const user = await db . query ( 'SELECT * FROM users WHERE email = ($1)' , [ email ] , ) ; if ( user . rowCount !== 1 ) return res . status ( 400 ) . send ( 'Invalid email or password' ) ; const validPassword = await bcrypt . compare ( password , user . rows [ 0 ] . password ) ; if ( ! validPassword ) return res . status ( 400 ) . send ( { status : 400 , error : "invalid email or password" } ) ; const token = jwt . sign ( { _id : user . rows [ 0 ] . id , _email : user . rows [ 0 ] . email , } , process . env . jwtPrivateKey ) ; res . send ( { status : 200 , data : [ { token } ] } ) ; }
POST /auth/login
 Route for login users
POST / auth / login Route for login users
// console.log(user); // await db.end();