import fs from 'fs-extra';
import path from 'path';
import os from 'os';
const CONFIG_DIR = path.join(os.homedir(), '.overleaf-mcp');
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
export class AuthManager {
constructor() {
this.ensureConfigDir();
}
async ensureConfigDir() {
await fs.ensureDir(CONFIG_DIR);
}
async saveConfig(config) {
const current = await this.getConfig();
const newConfig = { ...current, ...config };
await fs.writeJson(CONFIG_FILE, newConfig, { spaces: 2 });
}
async getConfig() {
if (await fs.pathExists(CONFIG_FILE)) {
return await fs.readJson(CONFIG_FILE);
}
return {};
}
async getCredentials() {
const config = await this.getConfig();
if (config.email && config.token) {
return { email: config.email, token: config.token };
}
return null;
}
}