Node.js / NestJS

JWT Authentication

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

25 питань зі співбесід·
Mid-Level
1

What is a JWT (JSON Web Token)?

Відповідь

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?

Відповідь

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?

Відповідь

@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 питань зі співбесід

Опануй Node.js / NestJS для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно