- Create Economist SubmissionTracking package correctly: * mainArticle = full blog post content * coverLetter = 216-word SIR— letter * Links to blog post via blogPostId - Archive 'Letter to The Economist' from blog posts (it's the cover letter) - Fix date display on article cards (use published_at) - Target publication already displaying via blue badge Database changes: - Make blogPostId optional in SubmissionTracking model - Economist package ID: 68fa85ae49d4900e7f2ecd83 - Le Monde package ID: 68fa2abd2e6acd5691932150 Next: Enhanced modal with tabs, validation, export 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.1 KiB
JavaScript
58 lines
1.1 KiB
JavaScript
/**
|
|
* JWT Utility
|
|
* Token generation and verification for admin authentication
|
|
*/
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const JWT_SECRET = process.env.JWT_SECRET || 'CHANGE_THIS_IN_PRODUCTION';
|
|
const JWT_EXPIRY = process.env.JWT_EXPIRY || '7d';
|
|
|
|
/**
|
|
* Generate JWT token
|
|
*/
|
|
function generateToken(payload) {
|
|
return jwt.sign(payload, JWT_SECRET, {
|
|
expiresIn: JWT_EXPIRY,
|
|
issuer: 'tractatus',
|
|
audience: 'tractatus-admin'
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Verify JWT token
|
|
*/
|
|
function verifyToken(token) {
|
|
try {
|
|
return jwt.verify(token, JWT_SECRET, {
|
|
issuer: 'tractatus',
|
|
audience: 'tractatus-admin'
|
|
});
|
|
} catch (error) {
|
|
throw new Error(`Invalid token: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Decode token without verification (for debugging)
|
|
*/
|
|
function decodeToken(token) {
|
|
return jwt.decode(token);
|
|
}
|
|
|
|
/**
|
|
* Extract token from Authorization header
|
|
*/
|
|
function extractTokenFromHeader(authHeader) {
|
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
return null;
|
|
}
|
|
return authHeader.substring(7);
|
|
}
|
|
|
|
module.exports = {
|
|
generateToken,
|
|
verifyToken,
|
|
decodeToken,
|
|
extractTokenFromHeader
|
|
};
|