The secret key must be a string for signing the token securely.
Step 2: Identify error in code
The code uses 12345 (a number) as secret key, which is incorrect.
Final Answer:
Secret key should be a string, not a number -> Option A
Quick Check:
Secret key type = string [OK]
Hint: Secret key must always be a string for jwt.sign() [OK]
Common Mistakes:
Passing number instead of string as secret key
Thinking payload must be string
Believing expiresIn is invalid
Assuming callback is mandatory
5. You want to create a JWT token that expires in 30 minutes and includes the user's email and role. Which code snippet correctly achieves this in Express?
The payload must include email and role from user object.
Step 2: Use correct expiresIn format
expiresIn accepts string like '30m' for 30 minutes; number means seconds but must be a number type without quotes.
Step 3: Identify correct option
Check each: expiresAt is invalid key; expireIn is misspelled; expiresIn: 30 is only 30 seconds. Only jwt.sign({ email: user.email, role: user.role }, 'mySecret', { expiresIn: '30m' }) is correct.