add forgiving API key validation with inline errors
Add KeyValidation module for format-checking API keys before attempting connections. Auto-strips whitespace, detects common mistakes (e.g. pasting a Stripe publishable key), and returns helpful error messages. Inline field errors across all three entry points: - Setup wizard: provider + Stripe keys - Admin provider form: simplified to single Connect button - Email settings: per-field errors instead of flash toasts Also: plain text inputs for all API keys (not password fields), accessible error states (aria-invalid, role=alert, thick border, bold text), inner_block slot declaration on error component. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,11 +82,11 @@ defmodule BerrypodWeb.Admin.EmailSettingsTest do
|
||||
|> form("form[phx-change=\"change_adapter\"]", %{email: %{adapter: "postmark"}})
|
||||
|> render_change()
|
||||
|
||||
# Submit with an API key
|
||||
# Submit with an API key (Postmark uses UUID format)
|
||||
html =
|
||||
view
|
||||
|> form("form[phx-submit=\"save\"]", %{
|
||||
email: %{adapter: "postmark", api_key: "pm_test_123"}
|
||||
email: %{adapter: "postmark", api_key: "abc12345-abcd-1234-abcd-123456789abc"}
|
||||
})
|
||||
|> render_submit()
|
||||
|
||||
@@ -108,7 +108,7 @@ defmodule BerrypodWeb.Admin.EmailSettingsTest do
|
||||
|> form("form[phx-submit=\"save\"]", %{email: %{adapter: "postmark", api_key: ""}})
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "Missing required fields"
|
||||
assert html =~ "API key is required"
|
||||
end
|
||||
|
||||
test "disconnect clears email configuration", %{conn: conn} do
|
||||
@@ -167,7 +167,7 @@ defmodule BerrypodWeb.Admin.EmailSettingsTest do
|
||||
|
||||
view
|
||||
|> form("form[phx-submit=\"save\"]", %{
|
||||
email: %{adapter: "postmark", api_key: "pm_new_key"}
|
||||
email: %{adapter: "postmark", api_key: "def12345-abcd-1234-abcd-123456789def"}
|
||||
})
|
||||
|> render_submit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user