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.
This commit is contained in:
Barrett Ruth 2026-03-07 03:46:34 -05:00
parent cb58062464
commit 30dc2363da
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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