Skip to content
Back to skills

Api Auth Guards

ASecurity

Generate authentication and authorization guards (JWT, API key, roles, permissions) with tenant context validation. Use when protecting API endpoints or implementing RBAC.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
securitybashapidatabase

Works with

  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill api-auth-guards --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Auth Guards?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Auth Guards
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-api-auth-guards/badge)](https://www.skillsdirectory.com/skills/david-li0406-api-auth-guards)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-auth-guards
description: Generate authentication and authorization guards (JWT, API key, roles, permissions) with tenant context validation. Use when protecting API endpoints or implementing RBAC.
allowed-tools:
  - Read
  - Write
  - Edit
  - Glob
  - Grep
---

# Auth Guards

## Purpose

Generate NestJS guards for authentication (JWT, API key) and authorization (roles, permissions) with tenant context validation.

## When to Use

- Protecting API endpoints with authentication
- Implementing role-based access control (RBAC)
- Adding permission checks
- Validating tenant context

## What It Generates

### Directory Structure

```
apps/api/src/common/guards/
├── jwt-auth.guard.ts
├── api-key.guard.ts
├── roles.guard.ts
├── permissions.guard.ts
├── tenant.guard.ts
└── index.ts
```

## Patterns Enforced

### JWT Authentication

Validates JWT tokens from `Authorization` header:

- Extracts and verifies JWT
- Attaches user to request object
- Validates token expiration

### API Key Authentication

Validates API keys from `x-api-key` header:

- Checks key against database
- Attaches organization to request
- Validates key is active

### Role-Based Authorization

Checks user roles from JWT:

- Supports multiple roles per user
- Hierarchical roles (admin > user)
- Custom role metadata

### Permission-Based Authorization

Checks user permissions:

- Fine-grained permissions (e.g., `users:read`, `users:write`)
- Resource-level permissions
- Tenant-scoped permissions

### Tenant Validation

Ensures tenant context is present:

- Validates `x-organization-id` header
- Checks user belongs to tenant
- Prevents cross-tenant access

## Usage Example

```bash
/skill auth-guards --type=jwt,roles,tenant --roles='admin,user,moderator'
```

## Related Files

- [Decorator Custom](../decorator-custom/SKILL.md) - Decorators for guards
- [API Controller](../../core/api-controller/SKILL.md) - Controllers with guards

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…