Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(core): add auth-store module to read local auth data

yushenec413effb92f
diff --git a/packages/core/src/hub/auth-store.ts b/packages/core/src/hub/auth-store.ts
new file mode 100644
index 0000000000..ff2342ba0f
--- /dev/null
+++ b/packages/core/src/hub/auth-store.ts
@@ -0,0 +1,34 @@
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+import { DATA_DIR } from "@multica/utils";
+
+const AUTH_FILE_PATH = join(DATA_DIR, "auth.json");
+
+export type LocalAuthData = { sid: string; deviceId: string };
+
+/**
+ * Read sid and deviceId from ~/.super-multica/auth.json.
+ * Returns null if the file is missing, unreadable, or incomplete.
+ */
+export function getLocalAuth(): LocalAuthData | null {
+ try {
+ const raw = readFileSync(AUTH_FILE_PATH, "utf8").trim();
+ if (!raw) return null;
+
+ const data = JSON.parse(raw);
+ if (
+ typeof data !== "object" ||
+ data === null ||
+ typeof data.sid !== "string" ||
+ !data.sid ||
+ typeof data.deviceId !== "string" ||
+ !data.deviceId
+ ) {
+ return null;
+ }
+
+ return { sid: data.sid, deviceId: data.deviceId };
+ } catch {
+ return null;
+ }
+}
diff --git a/packages/core/src/hub/index.ts b/packages/core/src/hub/index.ts
index 0b47e70530..671f72bdca 100644
--- a/packages/core/src/hub/index.ts
+++ b/packages/core/src/hub/index.ts
@@ -1,4 +1,5 @@
export { Hub } from "./hub.js";
export type { MessageSource, InboundMessageEvent } from "./hub.js";
export { getHubId } from "./hub-identity.js";
+export { getLocalAuth, type LocalAuthData } from "./auth-store.js";
export type { HubOptions } from "./types.js";