40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { Module, Global, OnModuleInit } from '@nestjs/common';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { AuthService } from './auth.service';
|
|
import { Tenant } from './entities/tenant.entity';
|
|
import { ApiKey } from './entities/api-key.entity';
|
|
import { RedisModule } from '../common/redis.module';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { TenantController } from './tenant.controller';
|
|
import { FirebaseAdminService } from './firebase-admin.service';
|
|
import { FirebaseAuthGuard } from './guards/firebase-auth.guard';
|
|
|
|
@Global()
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forFeature([Tenant, ApiKey]),
|
|
RedisModule,
|
|
],
|
|
controllers: [TenantController],
|
|
providers: [AuthService, FirebaseAdminService, FirebaseAuthGuard],
|
|
exports: [AuthService, FirebaseAdminService, FirebaseAuthGuard],
|
|
})
|
|
export class AuthModule implements OnModuleInit {
|
|
constructor(
|
|
private readonly authService: AuthService,
|
|
private readonly configService: ConfigService,
|
|
) {}
|
|
|
|
/**
|
|
* Seed the default API key from environment to prevent breaking current integrations.
|
|
* دمج مفتاح الأمان الافتراضي من الإعدادات لمنع توقف الرقابة الحالية
|
|
*/
|
|
async onModuleInit() {
|
|
const defaultKey = this.configService.get<string>('MAP_API_KEY');
|
|
if (defaultKey) {
|
|
await this.authService.seedDefaultKey('Default System', 'admin@intaleq.xyz', defaultKey);
|
|
console.log('✅ Default System API Key seeded successfully');
|
|
}
|
|
}
|
|
}
|