Skip to content

Build your personal knowledge base with Trilium Notes

feat(setup): prefill the sync server form when returning after a failed attempt

Elian Doran078f6e563b55
diff --git a/apps/client/src/setup.tsx b/apps/client/src/setup.tsx
index 9229af523e..fd49cf0b9f 100644
--- a/apps/client/src/setup.tsx
+++ b/apps/client/src/setup.tsx
@@ -415,6 +415,23 @@ function SyncFromServer({ setState }: { setState: (state: State) => void }) {
const [ isWrongPassword, setIsWrongPassword ] = useState(false);
const isValid = syncServerHost.trim() !== "" && password !== "";
+ useEffect(() => {
+ // After a failed attempt the sync options are already stored in the partial DB
+ // and exposed by setup/status — prefill so the user coming back from the failure
+ // screen only has to correct what's wrong (the password is never stored). The
+ // functional updates keep anything the user already typed.
+ server.get<{ syncServerHost?: string; syncProxy?: string }>("setup/status").then((status) => {
+ if (status.syncServerHost) {
+ setSyncServerHost((current) => current || status.syncServerHost || "");
+ }
+ if (status.syncProxy) {
+ setSyncProxy((current) => current || status.syncProxy || "");
+ }
+ }).catch(() => {
+ // Prefill is best-effort only.
+ });
+ }, []);
+
function raiseError(message: string) {
setError(message);
setErrorId(id => id + 1);
diff --git a/packages/trilium-core/src/routes/api/setup.spec.ts b/packages/trilium-core/src/routes/api/setup.spec.ts
index 39a2dee4b0..d410b6630a 100644
--- a/packages/trilium-core/src/routes/api/setup.spec.ts
+++ b/packages/trilium-core/src/routes/api/setup.spec.ts
@@ -33,6 +33,19 @@ describe("Setup API (core)", () => {
expect(res.body.syncVersion).toBe(appInfo.syncVersion);
});
+ it("includes the stored sync server so a failed setup can prefill the form, but only pre-initialization", async () => {
+ vi.spyOn(sqlInit, "isDbInitialized").mockReturnValue(false);
+ const res = await api.get<{ syncServerHost?: string; syncProxy?: string }>("/api/setup/status");
+ // The fixture stores empty strings; presence of the keys is the contract.
+ expect(res.body.syncServerHost).toBeDefined();
+ expect(res.body.syncProxy).toBeDefined();
+ });
+
+ it("omits the sync server once initialized — setup/status is unauthenticated", async () => {
+ const res = await api.get<{ syncServerHost?: string }>("/api/setup/status");
+ expect(res.body.syncServerHost).toBeUndefined();
+ });
+
it("creates a new document (createInitialDatabase stubbed)", async () => {
const createInitial = vi.spyOn(sqlInit, "createInitialDatabase").mockResolvedValue(undefined);
const res = await api.post("/api/setup/new-document", { query: { skipDemoDb: "1" } });
diff --git a/packages/trilium-core/src/routes/api/setup.ts b/packages/trilium-core/src/routes/api/setup.ts
index 18ca3ef2e5..7c924f05c2 100644
--- a/packages/trilium-core/src/routes/api/setup.ts
+++ b/packages/trilium-core/src/routes/api/setup.ts
@@ -2,14 +2,28 @@ import sqlInit from "../../services/sql_init.js";
import setupService from "../../services/setup.js";
import { getLog } from "../../services/log.js";
import appInfo from "../../services/app_info.js";
+import optionService from "../../services/options.js";
import type { Request } from "express";
import { SetupSyncFromServerResponse } from "@triliumnext/commons";
function getStatus() {
+ const isInitialized = sqlInit.isDbInitialized();
+ const schemaExists = sqlInit.schemaExists();
+
return {
- isInitialized: sqlInit.isDbInitialized(),
- schemaExists: sqlInit.schemaExists(),
- syncVersion: appInfo.syncVersion
+ isInitialized,
+ schemaExists,
+ syncVersion: appInfo.syncVersion,
+ // After a FAILED sync-from-server attempt the sync options are already stored in
+ // the partial DB; expose them so the wizard can prefill the form when the user
+ // goes back to correct it (#10548). Pre-initialization only: this endpoint is
+ // unauthenticated, and once the instance is live the host must not leak here.
+ ...(schemaExists && !isInitialized
+ ? {
+ syncServerHost: optionService.getOptionOrNull("syncServerHost") ?? "",
+ syncProxy: optionService.getOptionOrNull("syncProxy") ?? ""
+ }
+ : {})
};
}