Created
October 7, 2019 18:29
-
-
Save artemis15/d7e6100ebc4407d1cfd8c56aa77cdba6 to your computer and use it in GitHub Desktop.
Authgaurd with JWT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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