diff --git a/lib/core/connection/connect.js b/lib/core/connection/connect.js index bd10535466e..191b6c8446e 100644 --- a/lib/core/connection/connect.js +++ b/lib/core/connection/connect.js @@ -179,6 +179,9 @@ function prepareHandshakeDocument(authContext, callback) { } const authProvider = AUTH_PROVIDERS[credentials.mechanism]; + if (authProvider == null) { + return callback(new MongoError(`No AuthProvider for ${credentials.mechanism} defined.`)); + } authProvider.prepare(handshakeDoc, authContext, callback); return; }