Skip to content

feat(auth): introduce @nestjs-cls/auth plugin #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Papooch
Copy link
Owner

@Papooch Papooch commented May 8, 2025

No description provided.

@Papooch Papooch changed the base branch from main to feat/update-plugin-transactional May 8, 2025 20:22
@Papooch Papooch requested a review from Copilot May 8, 2025 20:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the @nestjs-cls/auth plugin, which adds an authorization mechanism to nestjs-cls by providing a RequirePermission decorator and associated tooling to enforce permission checks. Key changes include:

  • The implementation of the RequirePermission decorator and the custom PermissionDeniedException.
  • The creation of a plugin (ClsPluginAuth) to integrate the permission logic using CLS.
  • Updates to tests, documentation, and configuration files to support and verify the new functionality.

Reviewed Changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/auth/test/plugin-auth.spec.ts Adds a test verifying that a secured method throws PermissionDeniedException when permissions fail.
packages/auth/src/lib/require-permission.decorator.ts Implements the decorator logic using a Proxy and attaches method metadata.
packages/auth/src/lib/plugin-auth.ts Provides the new auth plugin for configuring and registering the CLS-based authorization.
packages/auth/src/lib/permission-denied.exception.ts Defines a custom exception for permission denial scenarios.
packages/auth/src/lib/auth.symbols.ts Manages unique symbols for differentiating auth contexts by name.
packages/auth/src/lib/auth.interfaces.ts Declares interface options for the RequirePermission decorator.
packages/auth/src/lib/auth-host.ts Hosts auth logic, manages CLS contexts, and provides permission verification.
packages/auth/src/index.ts Exports the plugin components and related classes.
packages/auth/jest.config.js Configures Jest to run tests for the plugin.
packages/auth/README.md Provides documentation and usage guidelines for the auth plugin.
Files not reviewed (2)
  • packages/auth/package.json: Language not supported
  • packages/auth/tsconfig.json: Language not supported
Comments suppressed due to low confidence (1)

packages/auth/test/plugin-auth.spec.ts:49

  • [nitpick] Consider adding a test case for scenarios where the permission predicate returns true, ensuring that the secured method returns the expected result. This will improve test coverage for successful authorization paths.
    it('should throw', async () => {

@Papooch Papooch force-pushed the feat/update-plugin-transactional branch from 1fae846 to 3a8a7b1 Compare May 12, 2025 20:50
@Papooch Papooch force-pushed the feat/auth-plugin branch from c7c14c2 to c9a678b Compare May 12, 2025 20:51
@Papooch Papooch force-pushed the feat/update-plugin-transactional branch from 3a8a7b1 to 0ac1261 Compare May 12, 2025 21:05
Base automatically changed from feat/update-plugin-transactional to main May 12, 2025 21:09
@Papooch Papooch force-pushed the feat/auth-plugin branch from c9a678b to f763423 Compare May 12, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant