Created
April 17, 2020 01:39
-
-
Save amerllica/bf3b9593cb64d1f17acbcb2af535022b to your computer and use it in GitHub Desktop.
reactjs server auth
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 jwt = require("jsonwebtoken"); | |
const secret = process.env.JWT_SECRET; | |
export const authCheck = (req, res, next) => { | |
if (req.headers.authorization) { | |
const token = req.headers.authorization; | |
jwt.verify(token, secret, (err, decoded) => { | |
if (err) { | |
res.send(401); | |
} else { | |
next(); | |
} | |
}); | |
} else { | |
res.send(401); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment