fix(server): inject ConfigService into ApiTokenGuard via useFactory#30
Merged
Conversation
tsx uses esbuild which does not emit TypeScript's emitDecoratorMetadata,
so Reflect.getMetadata('design:paramtypes', ApiTokenGuard) returns
undefined. Nest then instantiates the guard with no arguments, leaving
this.config undefined and crashing on every request.
Switching APP_GUARD from useClass to useFactory + inject makes the
dependency explicit and bypasses the metadata requirement entirely.
https://claude.ai/code/session_01TutexsuMCT24musZH7MH72
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Nest APP_GUARD registration for ApiTokenGuard to be constructed via a factory that injects ConfigService, enabling the guard to read runtime configuration.
Changes:
- Import
ConfigServiceinAppModule. - Replace the
APP_GUARDuseClassprovider with auseFactoryprovider that injectsConfigService.
Comment on lines
+55
to
+60
| providers: [ | ||
| { | ||
| provide: APP_GUARD, | ||
| useFactory: (config: ConfigService) => new ApiTokenGuard(config), | ||
| inject: [ConfigService], | ||
| }, |
There was a problem hiding this comment.
PR title doesn’t follow the Conventional Commits squash-merge format (<type>(<scope>): <imperative summary>) required by CONTRIBUTING.md. Please rename it to something like refactor(server): inject ConfigService into ApiTokenGuard (or another appropriate type/scope).
Owner
Author
There was a problem hiding this comment.
Fixed — PR title updated to fix(server): inject ConfigService into ApiTokenGuard via useFactory.
Generated by Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updated the
ApiTokenGuardprovider configuration to use a factory function that injects theConfigServicedependency, allowing the guard to access configuration at runtime.Key Changes
ConfigServicetoapp.module.tsApiTokenGuardprovider from a simple class provider to a factory providerConfigServiceas an injected dependency and passes it to theApiTokenGuardconstructorApiTokenGuardto access configuration values during authentication checksImplementation Details
The provider configuration was updated from:
To:
This change allows
ApiTokenGuardto be instantiated with configuration dependencies, making it more flexible for token validation logic that may depend on runtime configuration.https://claude.ai/code/session_01TutexsuMCT24musZH7MH72