diff --git a/lib/config.mjs b/lib/config.mjs index e18fdd9..2170557 100644 --- a/lib/config.mjs +++ b/lib/config.mjs @@ -86,10 +86,16 @@ export async function writeProfile(profileName, profileConfig) { await writeFile(configFile, ini.stringify(config)); } -export async function getSession(sessioName) { +export async function getSession(sessionName) { const config = ini.parse(await readFile(configFile, "utf-8")); + const key = ("sso-session " + sessionName).trim(); - return config["sso-session " + sessioName]; + if (!config[key]) { + console.log(`Key "${key}" not found in ${configFile}`); + process.exit(1); + } + + return config[key]; } export async function getCurrentSession() { @@ -137,7 +143,12 @@ export async function readAccountCache(sessionName) { } catch (_) { return []; } - return JSON.parse(await readFile(cacheFile, "utf8")); + + try { + return JSON.parse(await readFile(cacheFile, "utf8")); + } catch (_) { + return []; + } } export async function writeAccountCache(sessionName, accounts) {