diff --git a/config/config.example.json b/config/config.example.json index c560bcf..2e0d5c7 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -6,7 +6,8 @@ "name": "studybot", "auth": true, "username": "admin", - "password": "foobar" + "password": "foobar", + "authSource": "admin" }, "web": { diff --git a/src/models/config.ts b/src/models/config.ts index 32a9bd9..dd61fd4 100644 --- a/src/models/config.ts +++ b/src/models/config.ts @@ -22,6 +22,7 @@ export interface DatabaseConfig { auth: boolean; username?: string; password?: string; + authSource?: string; } export interface WebConfig { diff --git a/src/services/config.ts b/src/services/config.ts index bf72fff..cb69cdf 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -71,6 +71,9 @@ export class ConfigService { if(!this.config.database.password) { throw Error("Database auth is enabled but password is missing or empty."); } + if(!this.config.database.authSource) { + throw Error("Database auth is enabled but authSource is missing or empty."); + } } } diff --git a/src/services/database/database.ts b/src/services/database/database.ts index d2a7c8d..1ae4695 100644 --- a/src/services/database/database.ts +++ b/src/services/database/database.ts @@ -13,7 +13,8 @@ export class DatabaseService { this.mongooseInstance = await mongoose.connect(`mongodb://${dbConfig.address}/${dbConfig.name}`, { useNewUrlParser: true, useUnifiedTopology: true, - auth + auth, + authSource: dbConfig.authSource }); }