Skip to content

Commit 16761cd

Browse files
CoderCococlaude
andauthored
fix(server): inject ConfigService into ApiTokenGuard via useFactory (#30)
## Summary Updated the `ApiTokenGuard` provider configuration to use a factory function that injects the `ConfigService` dependency, allowing the guard to access configuration at runtime. ## Key Changes - Added import of `ConfigService` to `app.module.ts` - Changed `ApiTokenGuard` provider from a simple class provider to a factory provider - The factory function receives `ConfigService` as an injected dependency and passes it to the `ApiTokenGuard` constructor - This enables `ApiTokenGuard` to access configuration values during authentication checks ## Implementation Details The provider configuration was updated from: ```typescript providers: [{ provide: APP_GUARD, useClass: ApiTokenGuard }] ``` To: ```typescript providers: [ { provide: APP_GUARD, useFactory: (config: ConfigService) => new ApiTokenGuard(config), inject: [ConfigService], }, ] ``` This change allows `ApiTokenGuard` to 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 Co-authored-by: Claude <noreply@anthropic.com>
1 parent dd2cadd commit 16761cd

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

app/packages/server/src/app.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { APP_GUARD } from '@nestjs/core';
99
import type { Request, Response, NextFunction } from 'express';
1010
import { AwsModule } from './modules/aws.module.js';
1111
import { DiscordModule } from './modules/discord.module.js';
12+
import { ConfigService } from './services/ConfigService.js';
1213
import { GamesController } from './controllers/games.controller.js';
1314
import { ConfigController } from './controllers/config.controller.js';
1415
import { CostsController } from './controllers/costs.controller.js';
@@ -51,7 +52,13 @@ class RequestLoggerMiddleware implements NestMiddleware {
5152
FilesController,
5253
DiscordController,
5354
],
54-
providers: [{ provide: APP_GUARD, useClass: ApiTokenGuard }],
55+
providers: [
56+
{
57+
provide: APP_GUARD,
58+
useFactory: (config: ConfigService) => new ApiTokenGuard(config),
59+
inject: [ConfigService],
60+
},
61+
],
5562
})
5663
export class AppModule implements NestModule {
5764
/** Attaches the request logger to every route so each HTTP call emits one structured line. */

0 commit comments

Comments
 (0)