Skip to content

Instantly share code, notes, and snippets.

@amerllica
Created April 17, 2020 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amerllica/bf3b9593cb64d1f17acbcb2af535022b to your computer and use it in GitHub Desktop.
Save amerllica/bf3b9593cb64d1f17acbcb2af535022b to your computer and use it in GitHub Desktop.
reactjs server auth
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