fix(auth): Postgres as sole referral source of truth + web client gate - #41
Draft
EpicStarAi wants to merge 2 commits into
Draft
fix(auth): Postgres as sole referral source of truth + web client gate#41EpicStarAi wants to merge 2 commits into
EpicStarAi wants to merge 2 commits into
Conversation
Full snapshot of Replit workspace main branch (commit 5615a80) integrated onto GitHub origin/main (4ca2290) to establish shared commit history for review. Summary of changes vs GitHub main: - 440 files added (new features: artifacts/, epicgram/, packages/, etc.) - 85 files deleted (GitHub-only scaffolding replaced by monorepo structure) - 3 files modified (tsconfig.json, tsconfig.base.json, pnpm-lock.yaml) No force push. No production changes. Draft PR only.
Root cause: authData.ts swallowed DB errors silently (catch {}) and
fell through to a file fallback that had no codes, because
EPIC_DEV_REFERRAL was never set — so every referral attempt returned
'invalid' regardless of the code entered.
Changes:
- authData.ts: replace catch{} with proper error propagation when DB
is configured. Returns reason:'service_unavailable' instead of
silently falling to the file store. Postgres is the sole source of
truth when DATABASE_URL is set.
- gate/page.tsx (Next.js): add 'service_unavailable' to the error map.
- artifacts/api-server: add /api/auth/* routes (referral-login,
session, logout) backed by Postgres. Tables are created on first
call; EPIC_DEV_REFERRAL seeds one dev code if the table is empty.
- artifacts/epicgram-web: add /gate route (referral gate UI) and
protect /client with a session check — unauthenticated users are
redirected to /gate.
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.
Root cause
authData.tsswallowed every DB error with a barecatch {}and fell through to a file fallback that had no codes, becauseEPIC_DEV_REFERRALwas never set. Every referral attempt returnedinvalidregardless of what code the user entered.Additionally, the
referral_codestable had never been created in PostgreSQL (schema applied lazily on first call), and the Vite web client had no referral gate —/clientwas unprotected.Changes
epicgram/apps/web/lib/authData.tscatch {}with proper error propagation whenDATABASE_URLis configured.{ ok: false, reason: "service_unavailable" }instead of silently falling to file store.DATABASE_URLis absent entirely.referralLogin,getSession,logout.epicgram/apps/web/app/gate/page.tsxservice_unavailable→ "База данных недоступна — попробуйте позже".artifacts/api-server/src/lib/auth-db.ts(new)epicgram/apps/web/lib/authDb.ts.EPIC_DEV_REFERRALon first run.artifacts/api-server/src/routes/auth.ts(new)POST /api/auth/referral-login— validates code, issuesepic_sessionhttpOnly cookie.GET /api/auth/session— session status.POST /api/auth/logout— expires session + clears cookie.artifacts/epicgram-web/src/pages/Gate.tsx(new)/client. On existing session → skips.artifacts/epicgram-web/src/App.tsx/gateroute./clientwrapped inProtectedClient: unauthenticated →/gate.Test plan
EPIC_DEV_REFERRALsecret set ✅/gate→ enter dev referral code → expect redirect to/client./clientdirectly without session → expect redirect to/gate.Draft — do not merge or deploy without owner confirmation.