From 30dc2363dadacd7c6b9bb195f19c4c9e323a229b Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 7 Mar 2026 03:46:34 -0500 Subject: [PATCH] fix(credentials): cache credentials after prompt and clear cookies on logout Problem: \`prompt_and_login\` never called \`cache.set_credentials\` on success, so the fast path in \`M.login\` never triggered on subsequent calls. \`M.logout\` only cleared the plugin credentials cache, leaving browser cookie files on disk. Solution: call \`cache.set_credentials\` after a successful \`prompt_and_login\`. Add \`COOKIE_FILE\` constant and update \`M.logout\` to remove the platform's entry from the shared cookie file. --- lua/cp/constants.lua | 2 ++ lua/cp/credentials.lua | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lua/cp/constants.lua b/lua/cp/constants.lua index ec3c384..3a2e27d 100644 --- a/lua/cp/constants.lua +++ b/lua/cp/constants.lua @@ -219,4 +219,6 @@ M.LANGUAGE_VERSIONS = { M.DEFAULT_VERSIONS = { cpp = 'c++20', python = 'python3' } +M.COOKIE_FILE = vim.fn.expand('~/.cache/cp-nvim/cookies.json') + return M diff --git a/lua/cp/credentials.lua b/lua/cp/credentials.lua index 637ed23..cf3d29e 100644 --- a/lua/cp/credentials.lua +++ b/lua/cp/credentials.lua @@ -38,6 +38,7 @@ local function prompt_and_login(platform, display) end, function(result) vim.schedule(function() if result.success then + cache.set_credentials(platform, credentials) logger.log( display .. ' login successful', { level = vim.log.levels.INFO, override = true } @@ -105,6 +106,14 @@ function M.logout(platform) local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform cache.load() cache.clear_credentials(platform) + local cookie_file = constants.COOKIE_FILE + if vim.fn.filereadable(cookie_file) == 1 then + local ok, data = pcall(vim.fn.json_decode, vim.fn.readfile(cookie_file, 'b')) + if ok and type(data) == 'table' then + data[platform] = nil + vim.fn.writefile({ vim.fn.json_encode(data) }, cookie_file) + end + end logger.log(display .. ' credentials cleared', { level = vim.log.levels.INFO, override = true }) end