mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-26 00:46:44 -05:00
34 lines
633 B
TypeScript
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);
|
|
},
|
|
};
|
|
};
|