Commit Graph

31 Commits

Author SHA1 Message Date
e3a6641e3c fix: migrate AI chat system from Firebase/Firestore to Postgres
Firebase was not configured so every chat request crashed with
'Firebase Admin credentials not configured'.

- chat-mode-resolver.ts: read project phase from fs_projects (Postgres)
- chat-context.ts: load project data from fs_projects instead of Firestore
- /api/ai/conversation: store/retrieve conversations in chat_conversations
  Postgres table (created automatically on first use)
- /api/ai/chat: replace all Firestore reads/writes with Postgres queries
- v_ai_chat/page.tsx: replace Firebase client auth with useSession from
  next-auth/react; remove Firestore listeners, use REST API for project data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 12:07:03 -08:00
6668cc84fa fix: wrap useSearchParams in Suspense, add linux-musl prisma target
- useSearchParams() requires a Suspense boundary in Next.js App Router
- Prisma binaryTargets was missing linux-musl (alpine build environment)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:21:10 -08:00
1146d8d129 fix: correct Theia ForwardAuth redirect loop
Two issues:
1. ForwardAuth redirect used x-forwarded-host which Traefik sets to
   vibnai.com (the auth service host), not theia.vibnai.com. Now
   hardcodes THEIA_URL as the callbackUrl destination.
2. /auth page ignored callbackUrl and always sent users to
   /marks-account/projects. Now follows callbackUrl when it points
   to theia.vibnai.com, so users land in the IDE after login.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:17:16 -08:00
d00979f89e fix: use rows array returned by query(), not result.rows
db-postgres.ts query() returns T[] directly, not a QueryResult object.
result.rows was undefined, causing the session lookup to always
return null and redirect to login even with a valid session token.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 17:39:41 -08:00
c410c1759a debug: add logging to theia-auth session lookup
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 17:35:56 -08:00
008b04d2dd debug: add ?debug=1 endpoint to theia-auth for cookie inspection
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:57:49 -08:00
28cd9dd776 fix: correct snake_case column names in session lookup SQL
Prisma maps sessionToken → session_token and userId → user_id
in the PostgreSQL sessions table. The forwardAuth query was using
the wrong camelCase column names.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:53:32 -08:00
efcf20b8f6 fix: validate Theia auth via direct Postgres session lookup
Avoid importing authOptions/PrismaClient in the forwardAuth endpoint.
Under --network host (Coolify's build flag), routes that import Prisma
at module evaluation time are silently dropped from the build output.

Instead, read the NextAuth session-token cookie directly and verify
it with a raw SQL query against the sessions table - the same pattern
used by other working API routes via @/lib/db-postgres.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:33:47 -08:00
b9baefed0b fix: use getServerSession instead of getToken in theia-auth
next-auth/jwt subpath import causes Next.js to silently drop the
route from the standalone build output. Switch to getServerSession
which is used by all other working API routes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:28:22 -08:00
4e6fcbc566 fix: move forwardAuth endpoint to /api/theia-auth
NextAuth catches all /api/auth/* routes via [...nextauth] catch-all.
Move the Traefik forwardAuth endpoint to /api/theia-auth to avoid
the conflict. Traefik dynamic config updated to match.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:13:29 -08:00
22bf34c4e0 feat: add Traefik forwardAuth endpoint for Theia IDE
POST /api/auth/theia-check validates the NextAuth session cookie
forwarded by Traefik. Returns 200 for authenticated users with
X-Auth-User/Email/Name headers, or 302 redirect to /auth for
unauthenticated requests — preserving the original Theia URL as
callbackUrl so users land back in the IDE after login.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:10:56 -08:00
8bf69e1ae2 feat: update project dashboard UI for Vibn architecture
- project layout.tsx: replace Firebase Admin SDK with direct Postgres
  query to resolve project name; removes firebase/admin dependency
- overview page: full rewrite — fetches from /api/projects/:id, shows
  Gitea repo + last commit, branch, clone URLs; deployment status badge;
  open PRs and issues from contextSnapshot; recent commits list;
  resources section; Open IDE button; context freshness timestamp
- projects list page: cards now show Gitea repo + last commit inline,
  deploy status dot, IDE quick-link; updated empty state copy to reflect
  auto-provisioning; removed Firebase imports

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 14:57:16 -08:00
373bcee8c1 feat: Gitea auto-provisioning and webhook context sync
- Add lib/gitea.ts: Gitea API client (createRepo, createWebhook,
  deleteRepo, verifyWebhookSignature)
- Add lib/coolify.ts: Coolify API client (projects, databases,
  applications, deployments)
- Update api/projects/create: auto-creates a private Gitea repo and
  registers a webhook on every new project; stores giteaRepo,
  giteaRepoUrl, giteaCloneUrl, giteaSshUrl, giteaWebhookId in project
  data; Gitea errors are non-fatal so project creation still succeeds
- Add api/webhooks/gitea: handles push, pull_request, issues events;
  verifies HMAC signature; updates contextSnapshot on project record
- Add api/webhooks/coolify: handles deployment status events; updates
  contextSnapshot.lastDeployment on project record

Requires env vars: GITEA_API_URL, GITEA_API_TOKEN, GITEA_ADMIN_USER,
GITEA_WEBHOOK_SECRET, COOLIFY_URL, COOLIFY_API_TOKEN

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 14:48:46 -08:00
5831d19207 feat: rewrite projects page to use NextAuth session + Postgres API (remove Firebase) 2026-02-18 01:26:25 +00:00
f7bbf2ea5e feat: rewrite project delete to use NextAuth session + Postgres 2026-02-18 01:24:49 +00:00
59415bb0d9 feat: rewrite project GET/PATCH to use NextAuth session + Postgres 2026-02-18 01:24:48 +00:00
710a24a2fb feat: rewrite project create to use NextAuth session + Postgres 2026-02-18 01:24:47 +00:00
3fa242076b feat: add GET /api/projects using NextAuth + Postgres 2026-02-18 01:24:46 +00:00
934ac1cadf Fix: use client Providers wrapper instead of SessionProvider directly in root layout 2026-02-18 00:07:33 +00:00
b2e7c70d17 Add client-side Providers wrapper for SessionProvider 2026-02-18 00:07:23 +00:00
bbb22f1c37 Switch from SuperTokens to NextAuth.js
BREAKING CHANGE: Replace SuperTokens with NextAuth.js

Why:
- SuperTokens had persistent Traefik routing issues
- SSL certificate not issuing correctly
- Complex infrastructure (separate container)
- NextAuth runs in Next.js app (simpler, no separate service)

Changes:
- Install next-auth, @auth/prisma-adapter, prisma
- Create NextAuth API route: app/api/auth/[...nextauth]/route.ts
- Add Prisma schema for NextAuth tables (users, sessions, accounts)
- Update auth page to use NextAuth signIn()
- Remove all SuperTokens code and dependencies
- Keep same Google OAuth (just simpler integration)

Benefits:
- No separate auth service needed
- No Traefik routing issues
- Sessions stored in Montreal PostgreSQL
- Simpler configuration
- Battle-tested, widely used

All authentication data stays in Montreal!

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 15:12:21 -08:00
8cd95607a4 Fix Google OAuth: add redirectURIOnProviderDashboard parameter
- SuperTokens requires redirectURIOnProviderDashboard param
- Construct it from NEXT_PUBLIC_APP_URL or window.location.origin
- Properly encode the redirect URI in the query string
- Fixes 400 error: 'Please provide the redirectURIOnProviderDashboard'

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 12:47:00 -08:00
3d9a8498fc Remove simple landing page to use full marketing page
- Delete app/page.tsx to let app/(marketing)/page.tsx be the root
- Full marketing page has Hero, Features, Pricing, etc.
- Much better for vibnai.com root domain

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 11:34:45 -08:00
44895f9c31 Fix SuperTokens build error with lazy initialization
- Move SuperTokens.init() to runtime (not build time)
- Add dynamic route config to prevent build-time evaluation
- Move appInfo inside backendConfig function
- Update default URLs to vibnai.com

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 17:22:41 -08:00
c3bbc7818d Fix SuperTokens initialization timing issues
- Remove session check from home page (landing page doesn't need it)
- Add delayed session check in auth page to redirect logged-in users
- Handle SuperTokens not being initialized yet with proper error handling

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 16:15:03 -08:00
17dbcd36b9 Update home page with proper landing page and auth redirect
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 16:11:56 -08:00
0f8dbf8888 Fix SuperTokens to use separate ThirdParty and EmailPassword recipes
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 16:07:27 -08:00
abddadce94 Fix SuperTokens auth component for Google OAuth
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 16:02:18 -08:00
1ca3a68148 Update auth page to use SuperTokens
Replace Firebase auth with SuperTokens PreBuilt UI for seamless integration.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 15:58:52 -08:00
6764c1feb0 Add SuperTokens authentication integration
- Install supertokens-auth-react, supertokens-node, supertokens-web-js
- Create frontend and backend SuperTokens configuration
- Add API route handler for auth endpoints
- Add SuperTokensProvider wrapper in root layout
- Create new auth component with SuperTokens UI
- Configure Google and GitHub OAuth providers
- Ready for SuperTokens core deployment

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 15:27:40 -08:00
40bf8428cd VIBN Frontend for Coolify deployment 2026-02-15 19:25:52 -08:00