Node.js / NestJS

JWT Authentication

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

25 câu hỏi phỏng vấn·
Mid-Level
1

What is a JWT (JSON Web Token)?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

@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 câu hỏi phỏng vấn

Nắm vững Node.js / NestJS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí