Complete the code to import the JWT module in a NestJS service.
import { [1] } from '@nestjs/jwt';
The JwtService is imported from @nestjs/jwt to generate and validate tokens.
Complete the code to generate a JWT token with a payload.
const token = this.jwtService.[1](payload);The sign method creates a JWT token synchronously from the payload.
Fix the error in the code to verify a JWT token.
const payload = this.jwtService.[1](token);The verify method checks the token's validity and returns the decoded payload.
Fill both blanks to create a JWT token with expiration and secret options.
const token = this.jwtService.sign(payload, { [1]: '1h', [2]: 'mySecretKey' });The expiresIn option sets token expiry time, and secret defines the signing key.
Fill all three blanks to decode a token safely with error handling.
try { const payload = this.jwtService.[1](token, { [2]: 'mySecretKey' }); return payload; } catch (error) { throw new [3]('Invalid token'); }
Use verify to check the token with the secret. If invalid, throw UnauthorizedException to signal access denial.
