1234567891011121314151617181920212223242526272829303132333435 |
- const jwt = require("jsonwebtoken");
- const config = require("../configs/config.json");
- const verifyToken = (req, res, next) => {
- const token =
- req.body.token || req.query.token || req.headers["token"];
- if (!token) {
- return res.send({
- status:'tokenfalse',
- data:[{
- message: "A token is required for authentication"
- }],
- error:""
- });
- }
- try {
- const decoded = jwt.verify(token, config.token_header_key);
- req.user = decoded;
- } catch (err) {
- return res.send({
- status: 'tokenfalse',
- data:[{
- message: "Invalid Token"
- }],
- error:""
- });
-
- }
- return next();
- };
- module.exports = verifyToken;
|