Framework
Better Auth v1.5 + Express + TypeScript
Deploy Better Auth v1.5 as a shared authentication service on the Coolify server (159.195.68.41), replacing the custom magic-access server on the old server. All admin services on *.magicomniverse.online will be protected via Traefik forwardAuth with cross-subdomain SSO cookies.
Framework
Better Auth v1.5 + Express + TypeScript
Frontend
Vite + React + Tailwind (login/2FA pages)
Database
PostgreSQL (magic_auth on magic-postgres)
Repo
midego1/Magic-Auth (to be created)
| Item | Value |
|---|---|
| URL | https://auth.magicomniverse.online |
| Coolify Project | tools / production |
| Status | Planned (reviewed by Codex, 9 critical fixes incorporated) |
| Replaces | magic-access (old server, port 3334) |
| Users | 19 existing users (4 admin, 2 dev, 13 client) |
| Criteria | Better Auth | magic-access (current) | Keycloak | Authentik |
|---|---|---|---|---|
| Language | TypeScript | Node.js (custom) | Java | Python |
| Weight | ~5MB npm | ~Custom 1300 LOC | ~500MB Docker | ~800MB Docker |
| 2FA | TOTP + Email OTP (plugin) | WhatsApp + Email OTP (custom) | Built-in | Built-in |
| Device Trust | Built-in (2FA plugin) | Custom 64-char tokens | Built-in | Built-in |
| Multi-tenant | Organization plugin | Project-based (custom) | Realms | Tenants |
| Sessions | PostgreSQL-backed | In-memory (lost on restart) | Database | Database |
| Cross-service | Shared subdomain cookies | IP whitelist + nginx | OIDC/SAML | OIDC/SAML |
| Maintenance | Active (27.5k stars, v1.5.6) | Hand-rolled, single developer | Enterprise team | Community |
Browser visits any *.magicomniverse.online | Traefik Proxy (v3.6.11) | forwardAuth middleware --> auth.magicomniverse.online/api/verify | | | Valid session cookie? | / \ | YES NO | | | | 200 + headers 302 --> /login?redirect=... | | v | Target Service (user logs in, cookie set (portal, monitor, on .magicomniverse.online, price-import, etc.) redirect back)Cookie: better-auth.session_tokenDomain: .magicomniverse.online <-- shared across ALL subdomainsHttpOnly: true | Secure: true | SameSite: LaxOne login covers all protected services. No per-app auth code needed.
| Service | Current Auth | After |
|---|---|---|
| portal.magicomniverse.online | None (public) | forwardAuth |
| monitor.magicomniverse.online | None (public) | forwardAuth |
| price-import.magicomniverse.online | Basic Auth | forwardAuth |
| admin-*.magicomniverse.online | Medusa login | forwardAuth + Medusa login |
| terminal.magicomniverse.online | None | forwardAuth (+ WS handshake validation) |
| flowbuilder.magicomniverse.online | None | forwardAuth |
| n8n*.magicomniverse.online | n8n built-in | forwardAuth (webhooks excluded) |
| pim.magicomniverse.online | None | forwardAuth |
| Service | Why |
|---|---|
| auth.magicomniverse.online | The auth service itself (would loop) |
| Storefronts (brinxx, default, etc.) | Public customer-facing shops |
Webhook paths (n8n /webhook/*) | External integrations need access |
Internal services (*.internal) | Not publicly routable |
Codex identified that Traefik forwardAuth doesn’t auto-redirect on 401. The /api/verify endpoint returns a 302 redirect to the login page for browser requests, and 401 JSON for API/XHR requests (detected via Accept header).
Static API key (BREAK_GLASS_KEY env var) that bypasses auth entirely. If the auth service crashes, admins can still access services by passing X-Break-Glass header.
Services with public endpoints (n8n webhooks, health checks) use split Traefik routers: one public (no auth), one protected (with auth), differentiated by path prefix.
Existing bcryptjs hashes ($2a$ prefix, 10 rounds) must be verified compatible with Better Auth’s bcrypt implementation before building the migration script. This is a Day 0 pre-build checkpoint.
The auth service container is only reachable via the Coolify Docker network (Traefik proxy). No direct port mapping to the host.
Day 0: Pre-Build Verification
Phase 1: Core Auth Service
midego1/Magic-Auth repoauth.magicomniverse.onlinePhase 2: User Migration
magic_access.users)Phase 3: Service Protection (one at a time)
Phase 4: Cleanup
| Layer | Protection |
|---|---|
| Session cookies | HttpOnly, Secure, SameSite=Lax, domain-scoped |
| CSRF | SameSite + Better Auth built-in CSRF tokens |
| Brute force | Rate limiting (5 attempts / 15 min) |
| 2FA | TOTP (authenticator app) + Email OTP fallback |
| Trusted devices | 30-day device trust via 2FA plugin |
| Header spoofing | Traefik strips client X-Auth-* headers |
| Open redirect | Redirect URLs validated against trustedOrigins |
| Audit trail | All login/2FA/admin events logged |
| Break-glass | Emergency API key bypass for admin lockout |
| Review | Status | Findings |
|---|---|---|
| Codex Review | DONE | 30+ findings, 9 critical fixes incorporated |
| Eng Review | Pending | Recommended before implementation |
| CEO Review | — | — |
| Design Review | — | — |
magic-auth middleware from Traefik labels on affected service (per-service)ForwardAuth is per-service. Removing it from one service’s labels instantly removes auth for that service only. No global config to break.