Skip to content

Instantly share code, notes, and snippets.

@artemis15
Created October 7, 2019 18:29
Show Gist options
  • Save artemis15/d7e6100ebc4407d1cfd8c56aa77cdba6 to your computer and use it in GitHub Desktop.
Save artemis15/d7e6100ebc4407d1cfd8c56aa77cdba6 to your computer and use it in GitHub Desktop.
Authgaurd with JWT
const express = require('express');
const jwt = require('jsonwebtoken');
const config = require('../configs/config/config');
const authClientToken = async(req,res,next)=>{
let token = req.headers['x-access-token'];
if(!token)
{
return res.status(401).json({
'errors' : [{
'message' : " No Authentication token provided in Header"
}]
});
}
jwt.verify(token,config.secret,(error,decode) => {
if(error)
{
return res.status(401).json({
'errors' : [{
'message' : "Invalid Token"
}]
});
}
return next();
});
}
module.exports = {
authClientToken : authClientToken
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment