Skip to content

Commit

Permalink
Add authentication using authSource (#225)
Browse files Browse the repository at this point in the history
* Add authentication using authSource

* Fix formatting for 153e1a1
  • Loading branch information
Cosmiiko authored Aug 2, 2021
1 parent 7874818 commit 88dd176
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 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)
? data.pathname.substring(1)
: "admin",
db: new URLSearchParams(data.search).get("authSource") ??
((data.pathname && data.pathname.length > 1)
? data.pathname.substring(1)
: "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)
? data.pathname.substring(1)
: "admin";
connectOptions.db = new URLSearchParams(data.search).get("authSource") ??
(data.pathname && (data.pathname.length > 1)
? data.pathname.substring(1)
: "admin");
if (data.auth) {
connectOptions.credential = <Credential> {
username: data.auth.user,
Expand Down

0 comments on commit 88dd176

Please sign in to comment.