const responses = require('../helpers/responses');
const { validateToken } = require('../helpers/token');

const login = async (req, res, next) => {
    let token = req.headers.authorization;

    if (!token) return responses.failed(res, 404, 'token not found!');
    token = token.split('')[1];

    try {
        const validateTokenResult = validateToken(token);
        dataToken = validateTokenResult;
        // console.log(dataToken);
        next();
    } catch (error) {
        responses.failed(res, 500, error.message);
    }
};

module.exports = { login };
