Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
728 B
3
Indexable
Never
const router = require("express").Router();
const jwt = require("jsonwebtoken");
const config = require("../../../config.json");

router.post("/", (req, res) => {
    const { token } = req.body;
    if (!token) {
        return res.status(400).json({
            success: false,
            message: "No token provided."
        });
    }

    try {
        const decoded = jwt.verify(token, config.jwt_secret);
        return res.status(200).json({
            success: true,
            decoded
        });
    } catch (error) {
        return res.status(401).json({
            success: false,
            message: "Invalid or expired token.",
            error: error.message
        });
    }
});

module.exports = router;
Leave a Comment