This document outlines the major challenges encountered while building and testing this Auth0 + React + Docker e2e testing setup, along with the solutions that were implemented.
The Auth0 SPA SDK (@auth0/auth0-react) requires a secure origin (HTTPS) to function properly. When the React app was running on HTTP (http://app:3000), the Auth0 library would throw the error:
auth0-spa-js must run on a secure origin.Our options were either using https or localhost.
Let the e2e container use http://localhost:3000 to access the React app by adding network_mode: host in the docker-compose.yml.
services:
e2e:
network_mode: host # This was the key solution!
environment:
- CYPRESS_baseUrl=http://localhost:3000
- AUTH0_DOMAIN=https://localhost:4400Cypress tests needed to interact with both the main app (localhost:3000) and the Auth0 simulator (localhost:4400). This required proper multi-origin testing configuration.
cy.origin()Usage: Properly configuredcy.origin()calls for cross-origin interactions
cy.origin("https://localhost:4400", () => {
cy.get('[data-testid="simulator-login-button"]').click();
});The Auth0 simulator needed to be accessible from both the host browser and Docker containers, while maintaining proper hostname consistency for JWT tokens.
- Dual Binding: Configured the simulator to listen on
0.0.0.0:4400(accessible from containers) while returninghttps://localhost:4400as the issuer URL - JWT Token Consistency: Ensured JWT tokens always contained
https://localhost:4400as the issuer, regardless of how the simulator was accessed
The backend needed to verify JWT tokens from the Auth0 simulator using JWKS (JSON Web Key Set) endpoints, but encountered SSL certificate issues with self-signed certificates.
- SSL Bypass for JWKS: Temporarily disabled SSL certificate verification when fetching JWKS from the simulator
- Hono JWT Integration: Used Hono's
verifyWithJwksfunction for token verification - Error Handling: Implemented proper error handling for JWT verification failures
// Temporarily disable SSL certificate verification for self-signed certificates
const originalRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const payload = await verifyWithJwks(token, {
jwks_uri: `${process.env.VITE_AUTH0_DOMAIN}/.well-known/jwks.json`,
});The final working architecture consists of:
- App Service: HTTP backend serving React app on
http://localhost:3000 - Auth0 Simulator: HTTPS simulator on
https://localhost:4400 - E2E Service: Cypress container using
network_mode: hostto access host services - Proper CORS: Configured to allow cross-origin requests between services
- JWT Verification: Backend verifies tokens using JWKS from the simulator