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