fix auth
This commit is contained in:
@@ -39,7 +39,9 @@ const connectWithUri = async (uri, label) => {
|
||||
});
|
||||
|
||||
try {
|
||||
await connection.connection.db.admin().command({ ping: 1 });
|
||||
if (connection?.connection?.db) {
|
||||
await connection.connection.db.admin().command({ ping: 1 });
|
||||
}
|
||||
} catch (pingError) {
|
||||
if (isAuthError(pingError)) {
|
||||
await mongoose.connection.close().catch(() => {});
|
||||
@@ -49,10 +51,10 @@ const connectWithUri = async (uri, label) => {
|
||||
}
|
||||
|
||||
console.log('✅ MongoDB подключена успешно!');
|
||||
console.log(` Хост: ${connection.connection.host}`);
|
||||
console.log(` БД: ${connection.connection.name}\n`);
|
||||
console.log(` Хост: ${connection?.connection?.host || 'не указан'}`);
|
||||
console.log(` БД: ${connection?.connection?.name || 'не указана'}\n`);
|
||||
if (process.env.DEV === 'true') {
|
||||
console.log(` Пользователь: ${connection.connection.user || 'anonymous'}`);
|
||||
console.log(` Пользователь: ${connection?.connection?.user || 'anonymous'}`);
|
||||
}
|
||||
|
||||
return connection;
|
||||
|
||||
@@ -117,6 +117,9 @@ const waitForDatabaseConnection = async () => {
|
||||
|
||||
const verifyAuth = async () => {
|
||||
try {
|
||||
if (!mongoose.connection.db) {
|
||||
return false;
|
||||
}
|
||||
await mongoose.connection.db.admin().command({ listDatabases: 1 });
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user