Skip to content

fix(frontend): decouple frontend from backend internal URL#2202

Draft
bosbaber wants to merge 9 commits into
mainfrom
stephan/int1-654
Draft

fix(frontend): decouple frontend from backend internal URL#2202
bosbaber wants to merge 9 commits into
mainfrom
stephan/int1-654

Conversation

@bosbaber

@bosbaber bosbaber commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

At the heart of it, this this PR attempts to refactor the frontend package so that the BACKEND_INTERNAL_URL env variable is not inlined at build time anymore, but rather something that can be set at deploy time configuration.

We ran into this issue because we changed the name of the default backend service when trying to do a A/B deployment strategy. At this point we realised that the expected backend service name is baked into the image and cannot be configured compile time.

This PR attempts to rework the edge middleware so that it retrieves the URL to the internal backend service from the SSR side. This way built frontend images are no longer bound to very specific internal host names and topologies.

@bosbaber bosbaber self-assigned this Jun 8, 2026
@github-actions github-actions Bot added package: wallet/frontend Wallet frontend implementations type: source Source changes labels Jun 8, 2026
@bosbaber bosbaber requested a review from Copilot June 8, 2026 17:53
@github-actions github-actions Bot added the type: ci Changes to CI workflows label Jun 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the wallet frontend’s auth gating and internal-backend resolution so the frontend build is no longer coupled to a build-time-inlined BACKEND_INTERNAL_URL. It removes edge middleware-based auth checks and replaces them with SSR (getServerSideProps) wrappers that resolve the backend base URL at runtime via the shared HTTP client.

Changes:

  • Removed Next.js edge middleware.ts and moved auth/KYC/guest redirects into SSR wrappers (withAuth, withKyc, withGuest).
  • Updated many pages to use the SSR wrappers and to consume ctx.user instead of calling userService.me() in each page.
  • Stopped exposing BACKEND_INTERNAL_URL via next.config.js env inlining; SSR requests use runtime process.env.BACKEND_INTERNAL_URL through src/lib/httpClient.ts.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/wallet/frontend/src/pages/withdraw.tsx Switches SSR auth + user hydration to withAuth and ctx.user.
packages/wallet/frontend/src/pages/transactions.tsx Removes per-page me() call; uses withAuth and ctx.user.
packages/wallet/frontend/src/pages/settings/index.tsx Migrates to withAuth and uses ctx.user for settings props.
packages/wallet/frontend/src/pages/settings/developer-keys.tsx Migrates to withAuth and uses ctx.user for layout gating.
packages/wallet/frontend/src/pages/send.tsx Migrates to withAuth and removes duplicate me() call.
packages/wallet/frontend/src/pages/request.tsx Migrates to withAuth and removes duplicate me() call.
packages/wallet/frontend/src/pages/no-access.tsx Adds SSR auth gating via withAuth().
packages/wallet/frontend/src/pages/kyc.tsx Uses withKyc wrapper to enforce KYC-only access rules.
packages/wallet/frontend/src/pages/index.tsx Uses withAuth and consumes ctx.user for homepage props.
packages/wallet/frontend/src/pages/grants/index.tsx Uses withAuth and removes me() call.
packages/wallet/frontend/src/pages/grants/[grantId].tsx Uses withAuth and removes me() call for grant detail.
packages/wallet/frontend/src/pages/grant-interactions/index.tsx Uses withAuth wrapper for grant interaction SSR flow.
packages/wallet/frontend/src/pages/deposit.tsx Uses withAuth and ctx.user while still fetching GateHub iframe URL.
packages/wallet/frontend/src/pages/card.tsx Uses withAuth wrapper for card page SSR.
packages/wallet/frontend/src/pages/auth/verify/[token].tsx Uses withGuest wrapper for verify-email flow.
packages/wallet/frontend/src/pages/auth/signup.tsx Adds withGuest() SSR gating for signup.
packages/wallet/frontend/src/pages/auth/reset/[token].tsx Uses withGuest wrapper for password reset flow.
packages/wallet/frontend/src/pages/auth/login.tsx Adds withGuest() SSR gating for login.
packages/wallet/frontend/src/pages/auth/index.tsx Adds withGuest() SSR gating for auth welcome.
packages/wallet/frontend/src/pages/auth/forgot.tsx Adds withGuest() SSR gating for forgot-password.
packages/wallet/frontend/src/pages/account/create.tsx Uses withAuth and removes per-page me() call.
packages/wallet/frontend/src/pages/account/[accountId].tsx Uses withAuth and removes per-page me() call.
packages/wallet/frontend/src/middleware.ts Removes edge middleware-based auth gating entirely.
packages/wallet/frontend/src/lib/serverAuth.ts Introduces SSR auth/KYC/guest wrappers centralizing redirect logic.
packages/wallet/frontend/src/lib/httpClient.ts Ensures SSR base URL is read from runtime BACKEND_INTERNAL_URL.
packages/wallet/frontend/next.config.js Stops inlining BACKEND_INTERNAL_URL via env configuration.

Comment thread packages/wallet/frontend/src/lib/serverAuth.ts
@bosbaber bosbaber marked this pull request as draft June 8, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: wallet/frontend Wallet frontend implementations type: ci Changes to CI workflows type: source Source changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants