Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat: support API_MASTER_KEY env var for initial API key seed (#133)

gaussepic9b579ec2eda1
diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts
index 4b4d79f82..9146fe368 100644
--- a/src/modules/auth/auth.service.ts
+++ b/src/modules/auth/auth.service.ts
@@ -26,9 +26,11 @@ export class AuthService implements OnModuleInit {
let isNewKey = false;
if (count === 0) {
- // Use predictable key in development, random key in production
- displayKey =
- process.env.NODE_ENV === 'production' ? `owa_k1_${randomBytes(32).toString('hex')}` : 'dev-admin-key';
+ // Use env var if set, otherwise auto-generate predictable key in development, random key in production
+ displayKey = process.env.API_MASTER_KEY
+ || (process.env.NODE_ENV === 'production'
+ ? `owa_k1_${randomBytes(32).toString('hex')}`
+ : 'dev-admin-key');
await this.seedApiKey(displayKey, 'Default Admin Key', ApiKeyRole.ADMIN);
isNewKey = true;