From Broken Google OAuth to a Stable Sepolia E2E Environment: Engineering MyZubster on a VPS

Leader ●2 ●24 ●155
calendar_today • schedule9 min read

From Broken Google OAuth to a Stable Sepolia E2E Environment: Engineering MyZubster on a VPS

Over the last development cycle, we worked on stabilizing the MyZubster Sepolia environment and turning what was initially a collection of partially working services into a much more predictable end-to-end infrastructure.

The work involved several layers of the stack:

  • Node.js / Express backend
  • Google OAuth 2.0
  • React frontend
  • Ethereum Sepolia testing
  • MongoDB
  • PM2 process management
  • Cloudflare tunneling
  • VPS deployment
  • Environment configuration
  • Urban Lab / I-ECO-01 services
  • Git branch and deployment management

This article documents what we fixed, how we diagnosed the problems, what is working now, and what still needs to be completed.


1. The Starting Point

The Sepolia environment was running on a VPS with several services managed by PM2.

The main components included:

  • MyZubster Sepolia backend
  • MyZubster Sepolia frontend
  • MyZubster Social
  • MyZubster Web
  • Urban Lab / I-ECO-01
  • Cloudflared

The environment was operational, but two important areas were unstable.

The first was Google authentication.

Users could start the OAuth flow and Google returned the authorization callback, but the backend failed during the authorization-code exchange.

The second problem was the Urban Lab service.

It was trapped in a PM2 restart loop, generating millions of restarts because runtime dependencies required by server.js were missing.

We debugged these independently instead of treating the VPS as a single black box.


2. Debugging Google OAuth

The original application error was generic:

Login Google non riuscito

That message was not enough to identify whether the problem was caused by:

  • the authorization code,
  • OAuth state,
  • callback URI,
  • client ID,
  • client secret,
  • Google configuration,
  • proxy forwarding,
  • or application logic.

We therefore instrumented the token exchange temporarily.

The relevant backend flow exchanges the authorization code against Google's token endpoint and then retrieves the verified Google user profile.

The diagnostic logging revealed the actual failure:

status: 401
error: invalid_client
description: The provided client secret is invalid.

This immediately changed the investigation.

The callback itself was reaching the backend correctly.

The OAuth state existed.

The authorization code existed.

The problem was the credentials used during the token exchange.


3. Validating the Runtime Environment

One of the important lessons from this debugging session was that validating .env alone is not sufficient.

We checked both the configuration file and the running PM2 process.

The Google client configuration was inspected without printing the complete secret.

We verified properties such as:

CLIENT ID
SECRET PRESENT
SECRET LENGTH
SECRET FORMAT
CALLBACK URL

The configured callback was:

https://sepolia.myzubster.com/api/auth/social/google/callback

We then discovered that the previously configured secret was not a valid secret for the OAuth client being used.

After replacing it with the correct Google OAuth client secret, the token exchange started succeeding.


4. Google OAuth Successfully Completed

After correcting the OAuth credentials, the backend began reporting successful callbacks.

The flow became:

Browser
   |
   v
Google Authorization
   |
   v
/api/auth/social/google/callback
   |
   v
Authorization Code Exchange
   |
   v
Google Access Token
   |
   v
Google UserInfo
   |
   v
MyZubster account verification
   |
   v
Social login ticket
   |
   v
Frontend

The backend successfully received callbacks containing both the authorization code and OAuth state.

Most importantly, the previous invalid_client token error disappeared.

The public provider endpoint also confirmed:

{
  "success": true,
  "data": {
    "providers": {
      "google": true,
      "github": false,
      "facebook": false
    }
  }
}

Google authentication is therefore enabled in the Sepolia environment.


5. Fixing the OAuth Redirect

Authentication succeeding at Google was only part of the problem.

The backend was still redirecting successful logins to an old Vercel deployment.

The runtime destination was effectively:

old Vercel deployment

instead of:

https://sepolia.myzubster.com

We corrected the runtime environment so the relevant public URLs resolve to the Sepolia deployment.

The running PM2 process was verified with:

FRONTEND_URL=https://sepolia.myzubster.com
GATEWAY_PUBLIC_URL=https://sepolia.myzubster.com
PUBLIC_APP_URL=https://sepolia.myzubster.com

This was an important distinction.

Updating .env is not necessarily equivalent to updating the environment of an already running process.

For production-style deployments, the effective runtime configuration must always be verified.


6. Testing the Complete OAuth Path

We then tested the complete flow again.

The callback reached the backend with:

hasCode: true
hasState: true
hasError: false

The Google token exchange completed successfully.

No new Google token error appeared.

The backend remained online.

The provider endpoint remained available.

The PM2 process PID remained stable.

This gave us evidence that the fix was not simply masking an application crash.


7. Removing Temporary Debug Instrumentation

Temporary instrumentation is useful during incident analysis, but it should not become permanent application noise.

After confirming the OAuth path, we removed the temporary HTTP callback logger.

We retained useful error-level logging around OAuth failures:

console.error('[OAUTH-CALLBACK-ERROR]', {
  provider,
  message: String(error?.message || error)
});

This provides enough information for future troubleshooting without logging authorization codes, OAuth state values, access tokens, or secrets.

That distinction matters.

Authentication debugging must provide observability without accidentally creating a credential-leak mechanism.


8. Stabilizing Urban Lab / I-ECO-01

At the same time, another service on the VPS had a completely different problem.

The urbanlab PM2 process had accumulated an extremely large restart count.

Inspection of the error log showed:

Error: Cannot find module 'helmet'

The server required:

require('dotenv').config();
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const mongoose = require('mongoose');
const { createServer } = require('http');
const { Server } = require('socket.io');
const winston = require('winston');

But package.json originally contained only:

cors
dotenv
express
mongoose

The runtime therefore expected modules that the project did not declare/install.

We added the missing dependencies:

helmet
socket.io
winston

After installation, each required module could be resolved successfully.


9. Stopping a Multi-Million-Restart PM2 Loop

Once the missing dependencies were installed, Urban Lab started normally.

The server reported:

Server started on port 5002
MongoDB connected

Its health endpoint returned:

{
  "status": "ok",
  "service": "I-ECO-01",
  "mongodb": "connected"
}

We then compared the PM2 process before and after a waiting period.

The PID remained unchanged.

The restart counter remained unchanged.

That confirmed that the restart loop had actually stopped.

This is much more meaningful than simply seeing:

status: online

for a few seconds.

A process can repeatedly appear online while constantly crashing and restarting.

Process stability needs to be measured over time.


10. Current VPS Architecture

The resulting environment now looks approximately like this:

                    Internet
                       |
                       v
                Cloudflare Tunnel
                       |
                       v
            sepolia.myzubster.com
                       |
          +------------+------------+
          |                         |
          v                         v
     React Frontend            Express Backend
                                   |
                    +--------------+--------------+
                    |              |              |
                    v              v              v
                 MongoDB       Google OAuth   Sepolia EVM
                    |
                    v
              Application Data

Additional VPS services:

PM2
 |
 +-- MyZubster Sepolia Backend
 +-- MyZubster Sepolia Frontend
 +-- MyZubster Social
 +-- MyZubster Web
 +-- Urban Lab / I-ECO-01
 +-- Cloudflared

PM2 is configured under systemd, and the active process list has been saved using:

pm2 save

This means the current process configuration can be restored after a reboot through the existing PM2 startup integration.


11. Git Hygiene

Another important part of the work was separating debugging artifacts from actual source changes.

During debugging we created several temporary backups.

Before committing, those files were removed from the working tree.

We also explicitly verified that .env remained ignored.

The final source change was isolated and committed as:

fix(auth): improve OAuth callback error logging

The resulting commit was:

02f06f22

The working tree was clean after the commit.

The branch:

vps/sepolia-e2e-test

was then pushed to the remote repository.

This gives us a reproducible Git checkpoint corresponding to the working VPS state without committing the environment secrets.


12. Security Considerations

One of the most important lessons from this work concerns secrets.

OAuth client secrets, API keys, database credentials, private keys, GitHub tokens, JWT signing secrets, and similar credentials should never be committed to Git.

The repository correctly ignores .env.

But .gitignore is only one layer of protection.

The longer-term architecture should move production credentials toward dedicated secret management and controlled deployment-time injection.

We also deliberately avoided logging:

Google client secret
OAuth authorization code
OAuth state
access tokens
JWTs
database passwords
private keys

Observability and secret exposure must remain separate concerns.


13. What Is Working Now

At this stage we have achieved several concrete milestones.

Google OAuth can complete the server-side authorization-code flow.

The Sepolia backend exposes Google as an enabled authentication provider.

The callback is routed through the public Sepolia infrastructure.

The application runtime is using the intended Sepolia frontend/public URLs.

PM2 is running the MyZubster services.

PM2 configuration has been persisted.

Urban Lab / I-ECO-01 is no longer trapped in its missing-module restart loop.

Its MongoDB connection is operational.

The I-ECO-01 health endpoint responds successfully.

The OAuth debugging changes have been cleaned up.

The relevant source change has been committed and pushed to a dedicated branch.


14. What Still Needs to Be Done

A working OAuth callback does not mean the entire platform is production-ready.

Several areas still need engineering work.

Authentication hardening

The OAuth implementation should receive additional automated tests covering:

invalid state
expired state
missing code
provider errors
invalid client configuration
token endpoint failures
userinfo failures
unverified email
expired social-login tickets
replay attempts

GitHub and Facebook providers are currently disabled according to the provider endpoint and can be implemented or enabled separately when their configuration is ready.

Deployment reproducibility

The VPS currently represents an important working environment.

The next goal should be making that environment reproducible from source and configuration rather than depending on manual server history.

That means documenting and eventually automating:

dependency installation
environment injection
PM2 configuration
Cloudflare configuration
frontend startup
backend startup
health checks
rollback

Monitoring

A process being online is not sufficient operational monitoring.

We want visibility into:

restart rate
HTTP error rate
OAuth failure rate
MongoDB availability
response latency
memory consumption
CPU consumption
Sepolia RPC failures
WebSocket availability

Secret management

Production credentials should eventually be rotated and managed through a dedicated secret-management workflow.

CI/CD

The current branch and commit structure gives us a good foundation for moving toward automated deployment.

The desired flow is:

Developer
   |
   v
Git branch
   |
   v
Pull Request
   |
   v
Automated Tests
   |
   v
Security Checks
   |
   v
Merge
   |
   v
Sepolia Deployment
   |
   v
Health Checks
   |
   v
Production Promotion

15. Where We Want to Go

The objective is larger than simply making Google login work.

The Sepolia environment is becoming the integration layer where we can validate the interaction between identity, application state, Web3 payments, AI services, Urban Lab infrastructure, and MyZubster's broader ecosystem.

The architecture we are moving toward is approximately:

                         MyZubster
                             |
        +--------------------+--------------------+
        |                    |                    |
        v                    v                    v
     Identity             Web3 Layer          AI Layer
        |                    |                    |
   Google OAuth          Ethereum           AI Services
   GitHub OAuth          Sepolia            Zorgax / Pytho
   Social Identity       Wallets            Automation
        |                    |                    |
        +--------------------+--------------------+
                             |
                             v
                        Core Backend
                             |
             +---------------+---------------+
             |                               |
             v                               v
          MongoDB                       Urban Lab
                                            |
                                  +---------+---------+
                                  |                   |
                                  v                   v
                              IoT / GPS        Environmental Data

The Sepolia environment gives us a place to integrate these components without treating production as the testing environment.


16. Engineering Lessons

Several lessons from this debugging cycle are worth keeping.

Inspect the real provider response

Login failed tells you almost nothing.

401 invalid_client
The provided client secret is invalid

tells you exactly where to investigate.

.env is not necessarily the runtime environment

Always inspect what the actual process sees.

This becomes especially important with PM2, containers, systemd, CI/CD, and cloud deployment systems.

online does not necessarily mean healthy

Urban Lab demonstrated this clearly.

A service may be repeatedly restarted while PM2 continues reporting it as online between crashes.

PID stability, restart counters, health checks, and logs provide a much better picture.

Debug instrumentation should be temporary

Add enough instrumentation to understand the failure.

Verify the fix.

Then remove unnecessary diagnostic logging while retaining safe operational error reporting.

Infrastructure fixes should end in Git

A VPS fix that exists only in shell history is technical debt.

Once the behavior is verified, the corresponding source changes should be cleaned, reviewed, committed, and pushed.


Conclusion

What began as a Google login failure exposed several deeper infrastructure issues.

We traced the OAuth flow to the actual Google token exchange, identified an invalid client secret, corrected the runtime configuration, fixed the frontend redirect destination, validated the public callback path, cleaned the debugging instrumentation, stabilized a separate Urban Lab service that had entered a massive PM2 restart loop, verified MongoDB connectivity, persisted the PM2 process state, cleaned the Git working tree, committed the relevant OAuth changes, and pushed the working branch.

The important outcome is not simply:

“Google login works.”

The more important outcome is that the Sepolia environment is becoming observable, reproducible, testable, and suitable for real end-to-end integration work.

The next phase is to convert these manually validated infrastructure improvements into automated tests, deployment pipelines, monitoring, stronger secret management, and repeatable environment provisioning.

That is the path from a working development VPS to a maintainable engineering platform.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

ERC20 Edge Cases Every Smart Contract Engineer Should Know

BinnaDev - Jun 24

A Message From Our Founder: On the Winding Down of LaaSy™

Ken W. Algerverified - Oct 29

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

Cisco's Amy Chang: A Model's "Passport" Doesn't Tell You Where It Actually Came From

Tom Smithverified - Aug 27

The Privacy Gap: Why sending financial ledgers to OpenAI is broken

Pocket Portfolio - Feb 23
chevron_left
4.4k Points • 181 Badges
Rimini
112Posts
17Comments
33Connections

Commenters (This Week)

4 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!