Web, Android & Delivery
One Codebase, Two Build Targets That Disagree About Servers
Section 4 of 4
The application ships twice from one source tree: as a server-rendered Next.js deployment on Firebase App Hosting, and as a native Android application built from a static export and wrapped with Capacitor. Those two targets want incompatible things from the framework, and reconciling that without forking the codebase produced the most genuinely interesting build engineering in the project.
Phone authentication has the same shape of problem. The browser flow needs an invisible reCAPTCHA challenge; the native flow uses the platform's own verification and cannot use the web challenge at all. Both have to end at the same signed-in Firebase user.
2
build targets from one source tree
2
phone auth paths, one resulting session
0
credential files committed
1
server route in the whole application
Two Builds, One Source Tree
A static export cannot contain a server route. The web deployment needs one. Rather than deleting the route or maintaining a second codebase, the export build temporarily moves it aside and always puts it back.
Static export refuses to build if the application contains a non-static server route. The web deployment genuinely needs that route, because it is what keeps the team passwords off the client. Three options existed: delete the route and accept the vulnerability, fork the codebase for Android, or make the export build not see it.
The build script takes the third. It renames the API directory out of the tree, runs the export build with the export flag set, and renames it back.
The restore sits in a finally block, and that is the entire point of the script rather than an incidental detail. Without it, any failing Android build — a type error, an out-of-memory, an interrupted run — leaves the developer's working tree with the API route missing. They would then be debugging a web application whose team login has silently stopped existing, caused by a build they ran for a different platform. The failure would be confusing, would look like a bug in the application, and would be committed by anyone who did not notice.
A script that mutates a source tree has to be exception-safe, because the interesting case is not the one where it succeeds.
Everything here is readable
The security rules, the build script, the dual authentication paths and the hardening pass described across these four sections are all in the public repository, along with a README documenting exactly what was changed to publish it safely.
Read the Source on GitHub