Skip to content

Commit

Permalink
Add authentication using authSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmiiko committed Jul 31, 2021
1 parent 7874818 commit 153e1a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ export type SrvConnectOptions = Omit<ConnectOptions, "servers"> & {
export function parseSrvUrl(url: string): SrvConnectOptions {
const data = parse_url(url);
const connectOptions: SrvConnectOptions = {
db: (data.pathname && data.pathname.length > 1)
db: new URLSearchParams(data.search).get("authSource") ??
((data.pathname && data.pathname.length > 1)
? data.pathname.substring(1)
: "admin",
: "admin"),
};

if (data.auth) {
Expand Down Expand Up @@ -184,9 +185,10 @@ function parseNormalUrl(url: string): ConnectOptions {
server.port = server.port || 27017;
}

connectOptions.db = (data.pathname && data.pathname.length > 1)
connectOptions.db = new URLSearchParams(data.search).get("authSource") ??
(data.pathname && (data.pathname.length > 1)
? data.pathname.substring(1)
: "admin";
: "admin");
if (data.auth) {
connectOptions.credential = <Credential> {
username: data.auth.user,
Expand Down

0 comments on commit 153e1a1

Please sign in to comment.