fix(desktop):add auth cutover ipc

This commit is contained in:
Anish Sarkar 2026-06-24 03:55:39 +05:30
parent 766fa25ea0
commit 2fd7551d36
4 changed files with 73 additions and 16 deletions

View file

@ -0,0 +1,30 @@
import { app } from 'electron';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { secretStore } from './secret-store';
const CUTOVER_FLAG_FILE = 'auth-cutover-v1.json';
const REFRESH_TOKEN_KEY = 'surfsense_refresh_token';
async function hasCompletedCutover(flagPath: string): Promise<boolean> {
try {
const raw = await readFile(flagPath, 'utf8');
return JSON.parse(raw)?.complete === true;
} catch {
return false;
}
}
export async function purgeLegacyAuthCutover(): Promise<void> {
const userDataPath = app.getPath('userData');
const flagPath = path.join(userDataPath, CUTOVER_FLAG_FILE);
if (await hasCompletedCutover(flagPath)) return;
await secretStore.clear(REFRESH_TOKEN_KEY);
await mkdir(userDataPath, { recursive: true });
await writeFile(
flagPath,
JSON.stringify({ complete: true, completedAt: new Date().toISOString() }),
{ mode: 0o600 }
);
}