Created
January 13, 2021 16:15
-
-
Save polluterofminds/13c60a3cba4181dfc529a19aed0030ac to your computer and use it in GitHub Desktop.
Validate Endpoint
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
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