Skip to content

Commit 947c080

Browse files
committed
fix(ci): point both halves of a preview's account link at one SaaS
The browser read VITE_SAAS_API_URL from a variable while the backend kept its compiled-in default, so the two could name different SaaS deployments - or the frontend none at all while the log said "configured". Resolve one base and hand it to both, with the prod default as the fallback, which also makes the variable an optional override rather than something that has to be set. Metering stated off: previews point at prod, and accrual there would spend a real wallet. The 402 gate is independent of it and stays on.
1 parent c4ee120 commit 947c080

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

.github/workflows/PR-Auto-Deploy-V2.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,29 @@ jobs:
229229
id: saas
230230
env:
231231
PROJECT_REF: ${{ secrets.SAAS_DB_PROJECT_REF }}
232+
API_BASE_OVERRIDE: ${{ vars.SAAS_API_BASE_URL }}
232233
run: |
234+
# One value for both halves. The browser's reads and the backend's register/entitlement
235+
# calls have to land on the same SaaS, and nothing checks that they do. Optional, because
236+
# the backend already defaults to prod - set it only to point a preview elsewhere.
237+
API_BASE="${API_BASE_OVERRIDE:-https://stirling.com/app}"
238+
echo "backend_base=${API_BASE}" >> "$GITHUB_OUTPUT"
239+
233240
if [ -z "${PROJECT_REF}" ]; then
234241
echo "Not configured for this environment: the preview will build without a Stirling"
235242
echo "account, and the connect dialog will say so. To wire one up, set on the"
236-
echo "pr-preview environment: secrets SAAS_DB_PROJECT_REF and"
237-
echo "SAAS_SUPABASE_PUBLISHABLE_KEY (same Supabase project), and variable"
238-
echo "SAAS_API_BASE_URL."
243+
echo "pr-preview environment the secrets SAAS_DB_PROJECT_REF and"
244+
echo "SAAS_SUPABASE_PUBLISHABLE_KEY, both from the same Supabase project."
245+
# Moves with the Supabase pair, so an unconfigured preview stays wholly unconfigured
246+
# instead of aiming its reads at an account it cannot sign in to.
239247
echo "supabase_url=" >> "$GITHUB_OUTPUT"
248+
echo "frontend_base=" >> "$GITHUB_OUTPUT"
240249
else
241250
# Only whether, not which: the ref is a secret here, so Actions masks it out of any
242251
# line it appears in, derived URL included.
243-
echo "Stirling account configured."
252+
echo "Stirling account configured, at ${API_BASE}."
244253
echo "supabase_url=https://${PROJECT_REF}.supabase.co" >> "$GITHUB_OUTPUT"
254+
echo "frontend_base=${API_BASE}" >> "$GITHUB_OUTPUT"
245255
fi
246256
247257
- name: Check if image exists
@@ -272,7 +282,7 @@ jobs:
272282
BUILD_PORTAL=${{ env.BUILD_PORTAL }}
273283
VITE_SUPABASE_URL=${{ steps.saas.outputs.supabase_url }}
274284
VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY=${{ secrets.SAAS_SUPABASE_PUBLISHABLE_KEY }}
275-
VITE_SAAS_API_URL=${{ vars.SAAS_API_BASE_URL }}
285+
VITE_SAAS_API_URL=${{ steps.saas.outputs.frontend_base }}
276286
platforms: linux/amd64
277287

278288
- name: Set up SSH
@@ -306,9 +316,12 @@ jobs:
306316
environment:
307317
DISABLE_ADDITIONAL_FEATURES: "false"
308318
STIRLING_BILLING_ACCOUNT_LINK_ENABLED: "true"
319+
STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL: "${{ steps.saas.outputs.backend_base }}"
320+
# Off so preview traffic never accrues against a real wallet or trips its cap. The
321+
# 402 gate is separate and stays on, so gating is still testable here.
322+
STIRLING_BILLING_ACCOUNT_LINK_METERING_ENABLED: "false"
309323
# Stated rather than inferred from the request: the callback has to come back to the
310324
# preview hostname, not to the container's own :8080 behind this proxy.
311-
# account-link.saas-base-url is left alone; it already defaults to prod.
312325
SYSTEM_FRONTENDURL: "https://${V2_PORT}.ssl.stirlingpdf.cloud"
313326
SECURITY_ENABLELOGIN: "true"
314327
SECURITY_INITIALLOGIN_USERNAME: "${TEST_LOGIN_USERNAME}"

0 commit comments

Comments
 (0)