UNPKG

@backstageai/common

Version:

Common code for Backstage AI services

25 lines (18 loc) 524 B
// Middleware to check the JWT token const jwt = require("jsonwebtoken"); const checkAuth = (JWT_SECRET, authorization) => { if (!authorization || !authorization.startsWith("Bearer ")) { return null; } const token = authorization.split(" ")[1]; try { // Verify the token const decoded = jwt.verify(token, JWT_SECRET); // Return decoded token return decoded; } catch (err) { console.error("JWT verification failed:", err); return null; } }; module.exports.checkAuth = checkAuth;