Questions
12 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?
12 / 25

How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?

Difficulty: 6/10
field-level authorization, NestJS guards, GraphQL resolvers

Add a @ResolveField() for sensitive fields and check the requesting user's permissions inside the resolver. Return null when the user lacks permission. For ABAC-based field authorization, use CASL's ability.cannot() on the field name. This ensures sensitive data is never included in the response for unauthorized users.

Field-level authorization in GraphQL resolvers
Field-level authorization design notes:
  1. 1

    Return null for unauthorized fields — never throw an error; GraphQL partial results are expected.

  2. 2

    Declare the field as nullable: true in the schema so the null return is valid.

  3. 3

    @ResolveField() is lazy — it only runs when the client explicitly requests that field.

  4. 4

    Use GqlExecutionContext.create(context) in guards if applying field-level guards instead of resolver logic.

  5. 5

    CASL ability.cannot('read', subject, 'fieldName') checks the third argument as a field condition.

Scenario Questions

0-2 years experience

  1. 1We have a NestJS GraphQL resolver that returns a User object. How would you restrict the email field so only admins can see it?
  2. 2If you add a custom decorator @Roles('admin') to a field resolver, what steps are needed to make it enforce permission at runtime?

2-5 years experience

  1. 1You need to add field‑level permission checks to several resolvers, but the same logic repeats. How would you refactor to avoid duplication, and what trade‑offs does your approach have?
  2. 2During testing you notice that a non‑admin user still receives the 'salary' field even though you added a guard. What could be causing this, and how would you debug it?

5-8 years experience

  1. 1Our service now serves millions of GraphQL requests per day, and field‑level checks are adding latency. How would you redesign the permission system to maintain security while improving performance?
  2. 2We have multiple microservices each exposing GraphQL schemas, and we need a consistent field‑level authorization model across them. What architecture would you propose, and how would you handle policy updates?

8+ years experience

  1. 1The product roadmap includes exposing the GraphQL API to third‑party partners with custom permission sets. How would you evolve the current NestJS field‑level authorization to support dynamic, tenant‑specific policies without a massive code rewrite?
  2. 2Legacy resolvers use inline if‑statements for permissions, and you want to migrate to a declarative, policy‑driven approach. What migration strategy would you use to minimize risk and ensure backward compatibility?

Follow-up Questions

  • Can you walk me through the order in which NestJS executes guards and interceptors for a field resolver?
  • How would you test your field‑level authorization logic?
  • What are the security implications if you forget to apply the guard to a nested resolver?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.