/**
 * Auth routes
 */

const express = require('express');
const { registerSchema, loginSchema } = require('../utils/validators');
const { register, login } = require('../controllers/auth.controller');
const { validate } = require('../utils/validators');

const router = express.Router();

// Register
router.post('/register', registerSchema, (req, res, next) => {
  try {
    validate(req);
    return register(req, res).catch(next);
  } catch (e) {
    return next(e);
  }
});

// Login
router.post('/login', loginSchema, (req, res, next) => {
  try {
    validate(req);
    return login(req, res).catch(next);
  } catch (e) {
    return next(e);
  }
});

module.exports = router;

