Bird
Raised Fist0

You want to create a JWT that expires in 1 hour and includes the user's email. Which code snippet correctly achieves this?

hard🚀 Application Q8 of Q15
Rest API - Authentication and Authorization
You want to create a JWT that expires in 1 hour and includes the user's email. Which code snippet correctly achieves this?
Ajwt.sign({ email: 'user@example.com' }, 'secret', { expiresIn: '1h' })
Bjwt.sign({ email: 'user@example.com', exp: 3600 }, 'secret')
Cjwt.sign('user@example.com', 'secret', { expiresIn: 3600 })
Djwt.sign({ email: 'user@example.com' }, 'secret', { expiration: 3600 })
Step-by-Step Solution
Solution:
  1. Step 1: Use jwt.sign with payload and options

    The payload includes email; options set expiration with 'expiresIn' key.
  2. Step 2: Validate correct expiration format

    jwt.sign({ email: 'user@example.com' }, 'secret', { expiresIn: '1h' }) uses 'expiresIn: "1h"' which is the correct way to set 1 hour expiry.
  3. Final Answer:

    jwt.sign({ email: 'user@example.com' }, 'secret', { expiresIn: '1h' }) -> Option A
  4. Quick Check:

    Use expiresIn option with time string [OK]
Quick Trick: Use expiresIn: '1h' to set 1 hour expiry [OK]
Common Mistakes:
MISTAKES
  • Setting exp as number without correct format
  • Passing payload as string
  • Using wrong option key like 'expiration'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes