const jwt = require('jsonwebtoken');
// Step 1: Set the secret key for signing the JWT token
const secretKey = 'yourSecretKey';
// Step 2: Set the payload for the JWT token
const payload = {
userId: '123456',
username: 'john_doe',
};
// Step 3: Set the expiration time for the token in seconds
const expiresIn = 3600; // 1 hour
// Step 4: Generate the JWT token with the specified payload, secret key, and expiration time
const token = jwt.sign(payload, secretKey, { expiresIn });
// Step 5: Verify the token to check its authenticity and expiration
jwt.verify(token, secretKey, (err, decoded) => {
if (err) {
console.error('Token verification failed:', err.message);
} else {
console.log('Token verified. Decoded payload:', decoded);
}
});