Complete the code to import the JWT library.
const jwt = require('[1]');
The jsonwebtoken package is used to create and verify JWT tokens in Express.
Complete the code to create a JWT token with a payload.
const token = jwt.sign({ userId: 123 }, '[1]');The second argument to jwt.sign is the secret key used to sign the token.
Fix the error in the code to set token expiration to 1 hour.
const token = jwt.sign({ userId: 123 }, 'mysecretkey', { [1]: '1h' });The correct option to set token expiration is expiresIn.
Fill both blanks to verify a JWT token and extract the payload.
jwt.[1](token, 'mysecretkey', (err, [2]) => { if (err) { console.error('Invalid token'); } else { console.log([2]); } });
Use jwt.verify to check the token and the callback receives the decoded data, often named data.
Fill all three blanks to create a JWT token with user info, secret, and expiration.
const token = jwt.sign({ [1]: 'alice' }, '[2]', { [3]: '2h' });The payload key is 'username', the secret is 'supersecret', and the expiration option is 'expiresIn'.
