{"size": 387, "ext": "js", "max_stars_repo_path": "middleware/auth.js", "max_stars_repo_name": "ankur-agarwal/express-mongo-auth-routes", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "middleware/auth.js", "max_issues_repo_name": "ankur-agarwal/express-mongo-auth-routes", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "middleware/auth.js", "max_forks_repo_name": "ankur-agarwal/express-mongo-auth-routes", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.5, "max_line_length": 56, "alphanum_fraction": 0.6511627907}
const jwt = require('jsonwebtoken')

module.exports = function (req, res, next) {
	const token = req.header('token')
	if (!token) {
		return res.status(401).json({ message: 'Auth Error' })
	}

	try {
		const decoded = jwt.verify(token, 'randomString')
		req.user = decoded.user
		next()
	} catch (error) {
		console.error(error)
		res.status(500).send({ message: 'Invalid Token' })
	}
}
