Bird
0
0

You want to generate a JWT token that expires in 1 hour using JwtService. Which code snippet correctly sets the expiration?

hard📝 Application Q8 of 15
NestJS - Authentication
You want to generate a JWT token that expires in 1 hour using JwtService. Which code snippet correctly sets the expiration?
AjwtService.sign(payload, { expiresIn: '1h' })
BjwtService.sign(payload, { expiration: 3600 })
CjwtService.sign(payload, { expire: '60m' })
DjwtService.sign(payload, { timeout: 3600 })
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct option for expiration in sign()

    The correct option is expiresIn with string value like '1h'.
  2. Step 2: Eliminate incorrect option keys

    Options expiration, expire, and timeout are invalid keys for JwtService.
  3. Final Answer:

    jwtService.sign(payload, { expiresIn: '1h' }) -> Option A
  4. Quick Check:

    Expiration option = expiresIn [OK]
Quick Trick: Use expiresIn: '1h' to set token expiry time [OK]
Common Mistakes:
  • Using wrong option keys
  • Passing numbers without units
  • Confusing expire with expiresIn

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions