feat(credentials): re-prompt on bad credentials and improve cancel UX
Problem: After a failed login attempt, the user had to re-run `:CP <platform> login` manually. Cancel messages lacked context, and credential prompts in `submit.lua` used raw platform IDs instead of display names. Solution: `prompt_and_login` now recurses after failure so the user is re-prompted until they cancel or succeed. `submit.lua` extracts the scraper call into `do_submit` and re-prompts via `prompt_credentials` on `bad_credentials`. Username prompts show `<Esc> to cancel`, and cancel messages include the platform display name.
This commit is contained in:
parent
0c06b4a55a
commit
e3c81e895a
2 changed files with 21 additions and 11 deletions
|
|
@ -14,16 +14,16 @@ local STATUS_MESSAGES = {
|
|||
---@param platform string
|
||||
---@param display string
|
||||
local function prompt_and_login(platform, display)
|
||||
vim.ui.input({ prompt = '[cp.nvim]: ' .. display .. ' username: ' }, function(username)
|
||||
vim.ui.input({ prompt = '[cp.nvim]: ' .. display .. ' username (<Esc> to cancel): ' }, function(username)
|
||||
if not username or username == '' then
|
||||
logger.log('Cancelled', { level = vim.log.levels.WARN })
|
||||
logger.log(display .. ' login cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
vim.fn.inputsave()
|
||||
local password = vim.fn.inputsecret('[cp.nvim]: ' .. display .. ' password: ')
|
||||
vim.fn.inputrestore()
|
||||
if not password or password == '' then
|
||||
logger.log('Cancelled', { level = vim.log.levels.WARN })
|
||||
logger.log(display .. ' login cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -50,6 +50,7 @@ local function prompt_and_login(platform, display)
|
|||
display .. ' login failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
prompt_and_login(platform, display)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ local function prompt_credentials(platform, callback)
|
|||
callback(saved)
|
||||
return
|
||||
end
|
||||
vim.ui.input({ prompt = platform .. ' username: ' }, function(username)
|
||||
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
vim.ui.input({ prompt = '[cp.nvim]: ' .. display .. ' username (<Esc> to cancel): ' }, function(username)
|
||||
if not username or username == '' then
|
||||
logger.log('Submit cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
vim.fn.inputsave()
|
||||
local password = vim.fn.inputsecret(platform .. ' password: ')
|
||||
local password = vim.fn.inputsecret('[cp.nvim]: ' .. display .. ' password: ')
|
||||
vim.fn.inputrestore()
|
||||
vim.cmd.redraw()
|
||||
if not password or password == '' then
|
||||
|
|
@ -86,7 +87,7 @@ function M.submit(opts)
|
|||
end
|
||||
end
|
||||
|
||||
prompt_credentials(platform, function(creds)
|
||||
local function do_submit(creds)
|
||||
vim.cmd.update()
|
||||
|
||||
require('cp.scraper').submit(
|
||||
|
|
@ -112,16 +113,24 @@ function M.submit(opts)
|
|||
local err = result and result.error or 'unknown error'
|
||||
if err == 'bad_credentials' or err:match('^Login failed') then
|
||||
cache.clear_credentials(platform)
|
||||
logger.log(
|
||||
'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
prompt_credentials(platform, do_submit)
|
||||
else
|
||||
logger.log(
|
||||
'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
end
|
||||
logger.log(
|
||||
'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
end
|
||||
end)
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
prompt_credentials(platform, do_submit)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue