refactor(auth): simplify AdminGuard constructor and register it in AuthModule
The AdminGuard constructor is being simplified by using constructor parameter properties, rather than previously setting properties via Reflector in the constructor's body. Additionally, AuthModule now includes AdminGuard in its providers.
This commit is contained in:
parent
b9b2adb804
commit
3b201d63fe
@ -49,14 +49,10 @@ export class UserGuard implements CanActivate {
|
||||
|
||||
@Injectable()
|
||||
export class AdminGuard implements CanActivate {
|
||||
private readonly credentialService: CredentialsService;
|
||||
private readonly databaseService: DrizzleService;
|
||||
|
||||
constructor() {
|
||||
const reflector = new Reflector();
|
||||
this.credentialService = reflector.get<CredentialsService>('CredentialsService', UserGuard);
|
||||
this.databaseService = reflector.get<DrizzleService>('DrizzleService', UserGuard);
|
||||
}
|
||||
constructor(
|
||||
private readonly credentialService: CredentialsService,
|
||||
private readonly databaseService: DrizzleService
|
||||
) {}
|
||||
|
||||
async canActivate(
|
||||
context: ExecutionContext,
|
||||
|
@ -3,10 +3,11 @@ import { CredentialsModule } from "src/credentials/credentials.module";
|
||||
import { DrizzleModule } from "src/drizzle/drizzle.module";
|
||||
import { AuthController } from "./auth.controller";
|
||||
import { AuthService } from "./auth.service";
|
||||
import { AdminGuard } from "src/auth/auth.guard";
|
||||
|
||||
@Module({
|
||||
imports: [DrizzleModule, CredentialsModule],
|
||||
providers: [AuthService],
|
||||
providers: [AuthService, AdminGuard],
|
||||
controllers: [AuthController],
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user