Skip to content

Commit 3835cce

Browse files
committed
Fix authRequired function
If an error occurs because of missing authentication, it means that authentication is required.
1 parent 7630480 commit 3835cce

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

templates/mongoshrc.js.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ function rsReconfigSettings(settings){
1919
<% if @auth and @store_creds -%>
2020
function authRequired() {
2121
try {
22-
return db.serverCmdLineOpts().code == 13;
22+
return db.serverCmdLineOpts().ok != 1;
2323
} catch (err) {
24-
return false;
24+
if (err.message.match(/requires authentication/) || err.message.match(/not authorized on admin/)) {
25+
return true
26+
} else {
27+
throw("Unknown error :" + err)
28+
}
2529
}
2630
}
2731

0 commit comments

Comments
 (0)