New Sep 8, 2025

electron-store is not saving specific values

Libraries, Frameworks, etc. All from Newest questions tagged reactjs - Stack Overflow View electron-store is not saving specific values on stackoverflow.com

I cannot get these 2 new values to be stored in my cache.json file. I have tried to debug for 3 hours to no avail. I want to store

types.ts

export interface UserConfig {
  TMDB_API_KEY: string;
  SUPABASE_URL: string;
  SUPABASE_ANON_KEY: string;
  COMET_URL: string;
  MEDIAFUSION_URL: string;
}

These 5 values in my electron-store however only the first 3 values are stored rest are ignored.

cache.ts

import Store from "electron-store";

export const store = new Store({ schema: { TMDB_API_KEY: { type: "string", default: "" }, SUPABASE_URL: { type: "string", default: "" }, SUPABASE_ANON_KEY: { type: "string", default: "" }, COMET_URL: { type: "string", default: "" }, MEDIAFUSION_URL: { type: "string", default: "" }, }, });

preload.js

import { contextBridge, ipcRenderer } from "electron";
import { UserConfig } from "../shared/types.js";

contextBridge.exposeInMainWorld("electronAPI", { saveConfig: (config: UserConfig) => ipcRenderer.invoke("save", config), getConfig: () => ipcRenderer.invoke("get"), });

main.ts

import path from "path";
import { isDev } from "./util.js";
import { dirname } from "path/win32";
import { fileURLToPath } from "url";
import { store } from "./cache.js";
import { UserConfig } from "../shared/types.js";

const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename);

ipcMain.handle("save", (_event, config: UserConfig) => { store.set("TMDB_API_KEY", config.TMDB_API_KEY); store.set("SUPABASE_URL", config.SUPABASE_URL); store.set("SUPABASE_ANON_KEY", config.SUPABASE_ANON_KEY); store.set("COMET_URL", config.COMET_URL); store.set("MEDIAFUSION_URL", config.MEDIAFUSION_URL);

return { success: true }; });

ipcMain.handle("get", () => { return { TMDB_API_KEY: store.get("TMDB_API_KEY"), SUPABASE_URL: store.get("SUPABASE_URL"), SUPABASE_ANON_KEY: store.get("SUPABASE_ANON_KEY"), COMET_URL: store.get("COMET_URL"), MEDIAFUSION_URL: store.get("MEDIAFUSION_URL"), }; });

app.on("ready", () => { const mainWindow = new BrowserWindow({ titleBarStyle: "hidden", fullscreen: true, webPreferences: { preload: path.join(__dirname, "preload.js"), contextIsolation: true, nodeIntegration: false, sandbox: false, }, });

if (isDev()) { mainWindow.loadURL("http://localhost:5123"); } else { mainWindow.loadFile(path.join(app.getAppPath() + "/dist-react/index.html")); } });

Tried saving all values but only 3 are stored. I tried deleting the cache.json and my entire program's cache but it did not help. Please help me fix this

This is how I am calling it:

declare global {
  interface Window {
    electronAPI: {
      saveConfig: (config: UserConfig) => Promise<{ success: boolean }>;
      getConfig: () => Promise<UserConfig>;
    };
  }
}

export default function ConfigInputCard() { const [config, setConfig] = useState<UserConfig>({ TMDB_API_KEY: "", SUPABASE_URL: "", SUPABASE_ANON_KEY: "", COMET_URL: "", MEDIAFUSION_URL: "", });

const [showKeys, setShowKeys] = useState({ TMDB_API_KEY: false, SUPABASE_ANON_KEY: false, });

const [saveStatus, setSaveStatus] = useState< "idle" | "saving" | "success" | "error" >("idle");

useEffect(() => { if (window.electronAPI) { window.electronAPI .getConfig() .then((savedConfig) => { setConfig(savedConfig); }) .catch((error) => { console.error("Failed to load config:", error); }); } }, []);

const handleSave = async (e?: React.FormEvent) => { if (e) e.preventDefault();

if (!window.electronAPI) { console.error("Electron API not available"); setSaveStatus("error"); return; }

setSaveStatus("saving");

try { const result = await window.electronAPI.saveConfig(config); if (result.success) { setSaveStatus("success"); console.log("Configuration saved successfully!");

// Reset status after 2 seconds setTimeout(() => setSaveStatus("idle"), 2000); } else { setSaveStatus("error"); setTimeout(() => setSaveStatus("idle"), 3000); } } catch (error) { console.error("Failed to save config:", error); setSaveStatus("error"); setTimeout(() => setSaveStatus("idle"), 3000); } };

Scroll to top