Node.js / NestJS

JWT Authentication

Passport.js, JWT strategy, guards, bcrypt, refresh tokens, token expiration

25 perguntas de entrevistaยท
Mid-Level
1

What is a JWT (JSON Web Token)?

Resposta

A JWT is an open standard (RFC 7519) that defines a compact and secure format for transmitting information between parties as a JSON object. It is digitally signed to ensure its integrity and can be encrypted. JWTs are commonly used for stateless authentication in REST APIs because they contain all necessary information without requiring server-side sessions.

2

What is the structure of a JWT?

Resposta

A JWT consists of three parts separated by dots: Header (signature algorithm and type), Payload (claims/data), and Signature (integrity verification). Each part is Base64URL encoded. Example: eyJhbGc.eyJzdWI.SflKxwRJ. This structure allows transporting data while ensuring it hasn't been tampered with.

3

Which NestJS package is used to handle JWTs?

Resposta

@nestjs/jwt provides an abstraction around the jsonwebtoken package to facilitate JWT token generation and verification in NestJS. It integrates with the NestJS module system via JwtModule and exposes the JwtService with methods like sign(), signAsync(), verify() and verifyAsync(). It should be combined with @nestjs/passport for complete authentication.

4

What is the role of the JwtService.sign() method?

5

What is the role of the JwtService.verify() method?

+22 perguntas de entrevista

Domine Node.js / NestJS para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis