Files
better-auth/packages/electron/src/storage.ts
Joél Solano 1c9aab3bce feat: electron integration (#7647)
Co-authored-by: Alex Yang <himself65@outlook.com>
2026-02-04 20:37:05 +00:00

34 lines
633 B
TypeScript

import type { Options as ConfOptions } from "conf";
import Conf from "conf";
import electron from "electron";
import type { Storage } from "./client";
const { app } = electron;
export const storage = (
opts?: ConfOptions<Record<string, any>> | undefined,
): Storage => {
if (!app) {
return {
getItem: () => null,
setItem: () => {},
};
}
const config = new Conf({
cwd: app.getPath("userData"),
projectName: app.getName(),
projectVersion: app.getVersion(),
...opts,
});
return {
getItem: (key) => {
return config.get(key, null);
},
setItem: (key, value) => {
config.set(key, value);
},
};
};