Code Room
Code reviewHard
Question
Review this Node.js JWT verification middleware.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
const jwt = require('jsonwebtoken'); function authenticate(req, res, next) { const token = req.headers.authorization?.split(' ')[1]; const header = JSON.parse(Buffer.from(token.split('.')[0], 'base64').toString()); const decoded = jwt.verify(token, SECRET, { algorithms: [header.alg] }); req.user = decoded; next();}Run or narrate your approach, then ask the coach.