Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created January 13, 2021 16:15
Show Gist options
  • Save polluterofminds/13c60a3cba4181dfc529a19aed0030ac to your computer and use it in GitHub Desktop.
Save polluterofminds/13c60a3cba4181dfc529a19aed0030ac to your computer and use it in GitHub Desktop.
Validate Endpoint
import jwt from "jsonwebtoken";
const SECRET = "MY SUPER SECRET SIGNING KEY";
export const verifyToken = async (token) => {
try {
const verified = await jwt.verify(token, SECRET);
return verified;
} catch (error) {
throw error;
}
}
export default async (req, res) => {
try {
const verified = await verifyToken(req.body.token);
if(!verified) {
return res.status(404).send("Bad token");
}
res.status(200).send("OK");
} catch (error) {
console.log(error);
res.status(500).send("Server error");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment