fix(frontend): decouple frontend from backend internal URL#2202
Draft
bosbaber wants to merge 9 commits into
Draft
fix(frontend): decouple frontend from backend internal URL#2202bosbaber wants to merge 9 commits into
bosbaber wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
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.tsand moved auth/KYC/guest redirects into SSR wrappers (withAuth,withKyc,withGuest). - Updated many pages to use the SSR wrappers and to consume
ctx.userinstead of callinguserService.me()in each page. - Stopped exposing
BACKEND_INTERNAL_URLvianext.config.jsenv inlining; SSR requests use runtimeprocess.env.BACKEND_INTERNAL_URLthroughsrc/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.