fix(mongodb): expose authentication database
This commit is contained in:
1 parent
bae487867b
commit
f89b3a2bee
7 files changed
+143
-9
No files matched your search
@@ -17,6 +17,7 @@ import * as api from "@/lib/api";
|
||||
import { isTauriRuntime } from "@/lib/tauriRuntime";
|
||||
import { applyParsedConnectionUrl, parseConnectionUrl } from "@/lib/connectionUrl";
|
||||
import { connectionUrlPlaceholder as getUrlPlaceholder } from "@/lib/connectionPresentation";
|
||||
import { mongodbAuthFailureHint, mongoUrlParam, setMongoUrlParam } from "@/lib/mongoConnectionOptions";
|
||||
import { showAgentDriverInstallHint, type AgentDriverInstallState } from "@/lib/agentDriverInstallHint";
|
||||
import { ArrowLeft, ChevronRight, Copy, ExternalLink, FolderOpen, Grid3X3, Link2, List, Search } from "lucide-vue-next";
|
||||
|
||||
@@ -533,6 +534,18 @@ const testResultMessage = computed(() => {
|
||||
if (!testResult.value) return "";
|
||||
return testResult.value.ok ? t("connection.testSuccess") : testResult.value.message;
|
||||
});
|
||||
const mongoAuthDatabase = computed({
|
||||
get: () => mongoUrlParam(form.value.url_params, "authSource"),
|
||||
set: (value: string) => {
|
||||
form.value.url_params = setMongoUrlParam(form.value.url_params, "authSource", value);
|
||||
},
|
||||
});
|
||||
const mongoAuthMechanism = computed({
|
||||
get: () => mongoUrlParam(form.value.url_params, "authMechanism") || "default",
|
||||
set: (value: string) => {
|
||||
form.value.url_params = setMongoUrlParam(form.value.url_params, "authMechanism", value === "default" ? "" : value);
|
||||
},
|
||||
});
|
||||
|
||||
function goToConnectionStep(value = selectedType.value) {
|
||||
if (value !== selectedType.value) {
|
||||
@@ -565,7 +578,7 @@ async function testConnection() {
|
||||
testResult.value = { ok: true, message: msg };
|
||||
} catch (e: any) {
|
||||
if (runId !== testRunId) return;
|
||||
testResult.value = { ok: false, message: String(e) };
|
||||
testResult.value = { ok: false, message: mongodbAuthFailureHint(String(e)) };
|
||||
} finally {
|
||||
if (runId === testRunId) {
|
||||
isTesting.value = false;
|
||||
@@ -703,13 +716,13 @@ async function save() {
|
||||
emit("connectSucceeded", config.name);
|
||||
})
|
||||
.catch((e: any) => {
|
||||
emit("connectFailed", String(e?.message || e));
|
||||
emit("connectFailed", mongodbAuthFailureHint(String(e?.message || e)));
|
||||
});
|
||||
return;
|
||||
}
|
||||
open.value = false;
|
||||
} catch (e: any) {
|
||||
testResult.value = { ok: false, message: String(e?.message || e) };
|
||||
testResult.value = { ok: false, message: mongodbAuthFailureHint(String(e?.message || e)) };
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
@@ -1196,13 +1209,34 @@ function openExternalUrl(url: string) {
|
||||
<Input v-model="form.password" type="password" class="col-span-3" />
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label class="text-right">{{ t("connection.database") }}</Label>
|
||||
<Label class="text-right">{{ t("connection.defaultDatabase") }}</Label>
|
||||
<Input
|
||||
v-model="form.database"
|
||||
class="col-span-3"
|
||||
:placeholder="t('connection.databasePlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label class="text-right">{{ t("connection.authDatabase") }}</Label>
|
||||
<Input
|
||||
v-model="mongoAuthDatabase"
|
||||
class="col-span-3"
|
||||
:placeholder="t('connection.authDatabasePlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label class="text-right">{{ t("connection.authMechanism") }}</Label>
|
||||
<Select v-model="mongoAuthMechanism">
|
||||
<SelectTrigger class="col-span-3">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="default">{{ t("connection.authMechanismDefault") }}</SelectItem>
|
||||
<SelectItem value="SCRAM-SHA-1">SCRAM-SHA-1</SelectItem>
|
||||
<SelectItem value="SCRAM-SHA-256">SCRAM-SHA-256</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label class="text-right">{{ t("connection.urlParams") }}</Label>
|
||||
<Input
|
||||
|
||||
@@ -103,6 +103,11 @@ export default {
|
||||
database: "Database",
|
||||
databasePlaceholder: "Optional",
|
||||
databasePlaceholderWithDefault: "Optional, defaults to {database}",
|
||||
defaultDatabase: "Default DB",
|
||||
authDatabase: "Auth DB",
|
||||
authDatabasePlaceholder: "Optional, often admin",
|
||||
authMechanism: "Auth Mechanism",
|
||||
authMechanismDefault: "Default",
|
||||
serviceName: "Service/SID",
|
||||
driverName: "Driver Name",
|
||||
driverNamePlaceholder: "Vendor or environment name",
|
||||
@@ -180,7 +185,7 @@ export default {
|
||||
dmCompatHint: "Requires DM8 ODBC driver installed on your system.",
|
||||
dmDownload: "Download from Dameng",
|
||||
mongoLegacyHint:
|
||||
"MongoDB below 4.2 requires the MongoDB (Legacy) driver from Driver Manager; connections will switch automatically.",
|
||||
"MongoDB below 4.2 requires the MongoDB (Legacy) driver. If authentication fails and the user was created in admin, set Auth DB to admin.",
|
||||
compatible: "Compatible",
|
||||
mainstream: "Popular",
|
||||
color: "Color",
|
||||
|
||||
@@ -102,6 +102,11 @@ export default {
|
||||
database: "数据库",
|
||||
databasePlaceholder: "可选",
|
||||
databasePlaceholderWithDefault: "可选,默认 {database}",
|
||||
defaultDatabase: "默认库",
|
||||
authDatabase: "认证库",
|
||||
authDatabasePlaceholder: "可选,通常为 admin",
|
||||
authMechanism: "认证机制",
|
||||
authMechanismDefault: "默认",
|
||||
serviceName: "服务名/SID",
|
||||
driverName: "驱动名称",
|
||||
driverNamePlaceholder: "厂商或环境名称",
|
||||
@@ -177,7 +182,8 @@ export default {
|
||||
jdbcPluginHint: "先安装 DBX JDBC 插件,再导入数据库厂商提供的 JDBC 驱动 JAR。",
|
||||
dmCompatHint: "需要在系统上安装达梦 DM8 ODBC 驱动程序。",
|
||||
dmDownload: "前往达梦官网下载",
|
||||
mongoLegacyHint: "MongoDB 4.2 以下版本需在驱动管理中安装 MongoDB (Legacy) 驱动,连接时将自动切换。",
|
||||
mongoLegacyHint:
|
||||
"MongoDB 4.2 以下版本需安装 MongoDB (Legacy) 驱动。若账号创建在 admin 且认证失败,请将认证库设为 admin。",
|
||||
compatible: "兼容",
|
||||
mainstream: "主流",
|
||||
color: "颜色",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
export function mongoUrlParam(urlParams: string | undefined, key: string): string {
|
||||
const params = parseMongoUrlParams(urlParams);
|
||||
return params.get(key) || "";
|
||||
}
|
||||
|
||||
export function setMongoUrlParam(urlParams: string | undefined, key: string, value: string): string {
|
||||
const params = parseMongoUrlParams(urlParams);
|
||||
const normalized = value.trim();
|
||||
if (normalized) {
|
||||
params.set(key, normalized);
|
||||
} else {
|
||||
params.delete(key);
|
||||
}
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
export function mongodbAuthFailureHint(message: string): string {
|
||||
if (message.includes("Current authentication database:")) return message;
|
||||
|
||||
const source = message.match(/source='([^']+)'/)?.[1];
|
||||
if (!source || !message.includes("Exception authenticating MongoCredential")) return message;
|
||||
|
||||
return `${message}\n\nCurrent authentication database: ${source}. If this user was created in admin, set Authentication database to admin or add authSource=admin to URL params.`;
|
||||
}
|
||||
|
||||
function parseMongoUrlParams(urlParams: string | undefined): URLSearchParams {
|
||||
return new URLSearchParams((urlParams || "").trim().replace(/^\?/, ""));
|
||||
}
|
||||
Reference in new issue
Block a user