Questions
13 of 25
1How do you implement a local (username/password) Passport strategy in NestJS?
2How do you register a global JWT guard so all routes are protected by default in NestJS?
3What is RBAC and how do you implement a basic roles guard in NestJS?
4What is the difference between RBAC and ABAC and when would you use each in NestJS?
5How does the OAuth2 authorization code flow work and how do you implement it with Passport in NestJS?
6How do you implement API key authentication as an alternative to JWT in NestJS?
7How do you implement multi-tenant authentication where each tenant has its own JWT secret in NestJS?
8How do you implement JWT refresh token rotation with secure storage in NestJS?
9How do you implement ABAC with CASL in a NestJS application?
10What is the difference between JWT and session-based authentication and when do you choose each in NestJS?
11How do you implement two-factor authentication (2FA) with TOTP in NestJS?
12How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?
13How do you test authentication guards and strategies in NestJS?
14What is Passport.js and how does it integrate with NestJS?
15How do you implement row-level (resource-level) authorization to ensure users can only access their own records in NestJS?
16What is PKCE and when is it required in OAuth2 flows in NestJS?
17How do you implement an OAuth2 Authorization Server in NestJS?
18How do you implement session-based authentication in NestJS?
19How does the validate() method in a Passport strategy relate to the NestJS request lifecycle?
20How do you implement JWT authentication in NestJS with access and refresh tokens?
21What should and should not go inside a JWT payload?
22How do you implement JWT token revocation (blacklisting) without a database lookup on every request in NestJS?
23What is the difference between AuthGuard('jwt') from Passport and writing a custom JwtAuthGuard in NestJS?
24How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?
25How do you implement brute force protection on the login endpoint in NestJS?
13 / 25

How do you test authentication guards and strategies in NestJS?

Unit test guards by creating a TestingModule with a mocked Reflector and calling canActivate() directly with a mock ExecutionContext. E2E test the full auth flow using supertest — log in to get a real JWT, then assert that protected routes return 401 without it and 200 with it.

Guard unit test and auth e2e test
Auth testing strategy:
  1. 1

    Unit test guards by calling canActivate() directly with a mock ExecutionContext — no HTTP needed.

  2. 2

    Mock Reflector with jest.fn() and control getAllAndOverride return values per test case.

  3. 3

    E2E tests should use .overrideProvider() to swap UsersService with a mock — no real database needed.

  4. 4

    Always test both the unauthenticated (401) and authenticated (200) paths for protected routes.

  5. 5

    Test role-based routes with tokens carrying different role claims — assert 403 for insufficient roles.