fix setup flow stale state and Stripe URL issues
All checks were successful
deploy / deploy (push) Successful in 1m9s
All checks were successful
deploy / deploy (push) Successful in 1m9s
Onboarding: re-fetch setup_status() after provider/Stripe connect instead of manually patching the local assigns, which could miss admin_created and leave users stuck on the setup page with no way forward. Dev config: respect PHX_HOST for endpoint URL so Stripe checkout redirects to the correct host instead of always using localhost. Stripe setup: detect private/LAN IPs (10.x, 172.16-31.x, 192.168.x) as unreachable, not just localhost — prevents creating webhook endpoints that Stripe can never reach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2bd2e613c7
commit
e26a02a0fb
@ -21,6 +21,10 @@ config :berrypod, Berrypod.Repo,
|
||||
config :berrypod, BerrypodWeb.Endpoint,
|
||||
# Binding to loopback ipv4 address prevents access from other machines.
|
||||
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||
url: [
|
||||
host: System.get_env("PHX_HOST") || "localhost",
|
||||
port: String.to_integer(System.get_env("PORT") || "4000")
|
||||
],
|
||||
http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")],
|
||||
check_origin: false,
|
||||
code_reloader: true,
|
||||
|
||||
@ -79,12 +79,25 @@ defmodule Berrypod.Stripe.Setup do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns true if the app is running on localhost (Stripe can't reach it).
|
||||
Returns true if the app URL is unreachable from Stripe's servers
|
||||
(localhost, loopback, or private/LAN IPs).
|
||||
"""
|
||||
def localhost? do
|
||||
url = BerrypodWeb.Endpoint.url()
|
||||
uri = URI.parse(url)
|
||||
uri.host in ["localhost", "127.0.0.1", "0.0.0.0", "::1"]
|
||||
unreachable_host?(uri.host)
|
||||
end
|
||||
|
||||
defp unreachable_host?(host) when host in ["localhost", "0.0.0.0", "::1"], do: true
|
||||
|
||||
defp unreachable_host?(host) do
|
||||
case :inet.parse_address(String.to_charlist(host)) do
|
||||
{:ok, {127, _, _, _}} -> true
|
||||
{:ok, {10, _, _, _}} -> true
|
||||
{:ok, {172, b, _, _}} when b >= 16 and b <= 31 -> true
|
||||
{:ok, {192, 168, _, _}} -> true
|
||||
_ -> false
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_create_webhook(api_key) do
|
||||
|
||||
@ -150,12 +150,7 @@ defmodule BerrypodWeb.Setup.Onboarding do
|
||||
case Products.create_provider_connection(params) do
|
||||
{:ok, connection} ->
|
||||
Products.enqueue_sync(connection)
|
||||
|
||||
setup = %{
|
||||
socket.assigns.setup
|
||||
| provider_connected: true,
|
||||
provider_type: type
|
||||
}
|
||||
setup = Setup.setup_status()
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
@ -183,14 +178,7 @@ defmodule BerrypodWeb.Setup.Onboarding do
|
||||
|
||||
case StripeSetup.connect(api_key) do
|
||||
{:ok, _result} ->
|
||||
setup = %{socket.assigns.setup | stripe_connected: true}
|
||||
|
||||
setup =
|
||||
if setup.admin_created and setup.provider_connected do
|
||||
%{setup | setup_complete: true}
|
||||
else
|
||||
setup
|
||||
end
|
||||
setup = Setup.setup_status()
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|
||||
Loading…
Reference in New Issue
Block a user