This document outlines the migration from Clerk authentication to Neon Auth (powered by Stack Auth).
The application has been migrated to use Neon Auth, which provides seamless integration with Neon's PostgreSQL database and automatic user data synchronization.
-
Dependencies
- Removed:
@clerk/clerk-react - Added:
@stackframe/react
- Removed:
-
Configuration
- New Stack client configuration in
src/lib/stack.ts - Updated environment variables (see below)
- New Stack client configuration in
-
Components Updated
main.tsx: Now usesStackProviderinstead ofClerkProvideruseAppAuth.ts: Migrated to use Stack Auth hooksSignInPage.tsxandSignUpPage.tsx: Updated to use Stack Auth componentsNavigationSidebar.tsx: Uses Stack'sUserButtoncomponent- Added
StackHandler.tsxfor auth flow handling
-
Dependencies
- Added:
@stackframe/stack - Maintained:
@clerk/backend(for backward compatibility)
- Added:
-
Authentication Middleware
api/middleware/auth.js: Now supports both Clerk and Stack Auth tokens- Tries Stack Auth first, falls back to Clerk if needed
- Seamless transition for existing users
# Stack Auth Configuration
VITE_STACK_PROJECT_ID=your_stack_project_id
VITE_STACK_PUBLISHABLE_CLIENT_KEY=your_publishable_key
# Backend API
VITE_API_URL=http://localhost:3001
# Optional: Use custom auth forms
VITE_USE_BROWSER_AUTH=false# Stack Auth Configuration
STACK_PROJECT_ID=your_stack_project_id
STACK_SECRET_SERVER_KEY=your_secret_server_key
# Neon Database
DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
# Optional: Clerk (for backward compatibility)
# CLERK_SECRET_KEY=sk_test_...
# CLERK_JWT_KEY=...- Go to neon.tech and create a new project
- Copy your database connection string
- In the Neon Console, navigate to the Auth section
- Enable Neon Auth for your project
- Copy the Stack Auth credentials:
- Project ID
- Publishable Client Key
- Secret Server Key
- Update frontend
.envwith Stack Auth credentials - Update backend
.envwith Stack Auth and database credentials - Remove old Clerk environment variables (unless maintaining backward compatibility)
# Frontend
cd ai-notes-app
npm install
# Backend
cd ../ai-backend-service
npm install# Start backend
cd ai-backend-service
npm run dev
# Start frontend
cd ../ai-notes-app
npm run dev- Backend supports both Clerk and Stack Auth tokens
- Existing Clerk users can continue to authenticate
- Gradual migration path available
- Neon Auth automatically syncs user data to your database
- No need for manual user creation or webhooks
- Real-time updates across all user properties
- JWT tokens with customizable expiration
- Secure cookie-based token storage
- Built-in CSRF protection
- Unified Platform: Auth and database in one place
- Automatic Sync: User data always up-to-date in your database
- SQL Queries: Join user data directly with your application data
- Performance: Reduced latency with integrated services
- Cost Effective: Single billing for auth and database
-
Authentication fails
- Verify Stack Auth credentials are correct
- Check that the backend URL is accessible
- Ensure cookies are enabled in the browser
-
User data not syncing
- Check database connection string
- Verify Neon Auth is enabled in console
- Look for errors in backend logs
-
Migration from Clerk
- Keep Clerk keys during transition period
- Test with both auth providers
- Gradually migrate users