This project currently uses two authentication paths that map into the same
Neon PostgreSQL users table.
- Frontend login and registration call
POST /api/loginandPOST /api/register. - The API verifies passwords with
bcryptand signs JWTs withjsonwebtoken. - The frontend stores the JWT in
localStorageand sends it as a bearer token. - API routes use
requireAuth()fromapi/_lib/auth.js; that middleware checks the JWT path first.
- OAuth is handled by Stack Auth through the Neon Auth integration.
- The React app initializes
StackClientAppinapp/src/config/neonAuth.js. app/src/App.jsxwraps the app inStackProviderand exposes Stack Auth's callback handler at/handler/*.- The backend verifies Stack Auth sessions in
api/_lib/neon-auth.jsby calling Stack Auth's server API. - OAuth users are linked to local database users by
neon_auth_idfirst, then by email.
Neon PostgreSQL remains the application database. User-owned data is keyed to
users.id:
calculations.user_iduser_data.user_idcontributors.user_id
Any auth migration must preserve those relationships so saved calculations, custom yield data, and contributor profiles continue to sync across devices.
- Support OAuth providers such as Google and GitHub.
- Support email or password login for users who do not use OAuth.
- Persist identity across devices, not only in browser storage.
- Map every authenticated identity to the existing local user record.
- Keep
req.usercompatible with protected API routes that expectid,username, andemail. - Work with the selected hosting platform and Neon PostgreSQL.
Stack Auth OAuth redirects only work from domains registered in Stack Auth's
Trusted Domains settings. A deployed Vercel domain must be added there before
OAuth can complete. The callback route is /handler/*, but Stack Auth expects
the domain root to be trusted, not the full callback URL.
The Vercel integrations panel should only keep integrations that are actively used. Clerk is not referenced in this codebase, and duplicate Neon integrations make it harder to reason about which environment variables and auth project are active.
This is the lowest-code option. It keeps the current OAuth flow and local JWT password flow, but the team must maintain Trusted Domains and Vercel integration settings carefully.
Better Auth can consolidate email/password and OAuth into one self-hosted auth
system. The existing roadmap in docs/AUTH_MIGRATION_ROADMAP.md covers the
larger Stack Auth to Better Auth plus Cloudflare migration.
Clerk has strong React support and can run outside Vercel, but it is not wired into this repository today. Connecting Clerk would require replacing the current Stack Auth and JWT paths.
Auth.js is open source and provider-agnostic. It would require more adapter and session work than Stack Auth, but it avoids a hosted auth dependency.
Supabase Auth works well when the database is also Supabase. Using it here would introduce a second platform next to Neon unless the database is migrated too.
- Inventory current Vercel and Stack Auth environment variables.
- Register production and preview domains in Stack Auth Trusted Domains.
- Remove unused Clerk integration from Vercel.
- Remove stale duplicate Neon integrations after confirming env ownership.
- Choose whether to keep dual auth or consolidate into one provider.
- Preserve the
users.idmapping for calculations, custom data, and contributor profiles. - Test password login, OAuth login, logout, saved calculations, custom data, and contributor profile updates after any auth change.