A modern AI chat application built with Next.js, featuring multiple authentication methods and support for 6+ AI providers. Users can either sign in with OAuth (GitHub/Google) or bring their own API keys from their preferred AI provider.
- OAuth Authentication: Quick sign-in with GitHub or Google
- Bring Your Own API Key (BYOK): Use your own API keys from any supported provider
- Secure Storage: API keys encrypted with AES-256-GCM encryption
- OpenAI - GPT-3.5, GPT-4, and more
- Anthropic - Claude 3 models
- Google AI - Gemini Pro and variants
- Mistral AI - Mistral models
- Cohere - Command models
- OpenRouter - Access to 200+ models from multiple providers
- Real-time streaming responses
- Multiple conversations with persistent history
- Modern UI with dark/light theme support
- Responsive design for desktop and mobile
- Smart chat titles auto-generated from conversations
- Framework: Next.js 15 with App Router
- AI SDK: Vercel AI SDK for streaming responses
- Authentication: NextAuth.js v4
- Database: Drizzle ORM with SQLite (local) / Cloudflare D1 (production)
- UI: Tailwind CSS + shadcn/ui components
- Deployment: Cloudflare Pages compatible
- Node.js 18+ or Bun
- At least one AI provider API key (optional for OAuth users)
-
Clone the repository
git clone https://github.com/yourusername/chat.inja.online.git cd chat.inja.online -
Install dependencies
bun install
-
Set up environment variables
cp env.example .env.local
-
Configure environment (see Environment Configuration below)
-
Set up the database
# Generate database schema bun run db:generate # Apply migrations to local SQLite database bun run db:migrate:local
-
Start the development server
bun run dev
-
Open your browser Navigate to http://localhost:3000
Create a .env.local file with the following configuration:
# Application URL
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Node Environment
NODE_ENV="development"
# Database (Local SQLite - automatically created)
DATABASE_URL="file:./local.db"
# NextAuth Configuration
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-development-secret-key-min-32-chars"
# OAuth Providers (Required for OAuth login)
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# Cloudflare D1 (Not used in development, but required by env validation)
CLOUDFLARE_DATABASE_ID="placeholder-for-dev"
CLOUDFLARE_ACCOUNT_ID="placeholder-for-dev"
CLOUDFLARE_API_TOKEN="placeholder-for-dev"Set these in your Cloudflare Pages dashboard:
# Application URL
NEXT_PUBLIC_APP_URL="https://your-domain.pages.dev"
# Node Environment
NODE_ENV="production"
# Database URL (same as Cloudflare D1 connection)
DATABASE_URL="https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/d1/database/DATABASE_ID"
# NextAuth Configuration
NEXTAUTH_URL="https://your-domain.pages.dev"
NEXTAUTH_SECRET="your-production-secret-key-min-32-chars"
# OAuth Providers
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# Cloudflare D1 Database
CLOUDFLARE_DATABASE_ID="your-d1-database-id"
CLOUDFLARE_ACCOUNT_ID="your-cloudflare-account-id"
CLOUDFLARE_API_TOKEN="your-cloudflare-api-token"If deploying to Vercel, use these environment variables:
# Application URL
NEXT_PUBLIC_APP_URL="https://your-app.vercel.app"
# Node Environment
NODE_ENV="production"
# Database (Use your preferred database)
DATABASE_URL="your-production-database-url"
# NextAuth Configuration
NEXTAUTH_URL="https://your-app.vercel.app"
NEXTAUTH_SECRET="your-production-secret-key-min-32-chars"
# OAuth Providers
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# For Vercel, you might not need Cloudflare D1 variables
CLOUDFLARE_DATABASE_ID="not-used"
CLOUDFLARE_ACCOUNT_ID="not-used"
CLOUDFLARE_API_TOKEN="not-used"The app uses a simple SQLite database (local.db) for local development:
# Generate migrations from schema
bun run db:generate
# Apply migrations to local database
bun run db:migrate:local
# Open database studio for local development
bun run db:studio:localFor production deployment on Cloudflare Pages:
-
Create a D1 database
wrangler d1 create chat-inja-db
-
Update
wrangler.tomlwith your database ID -
Apply migrations to production
bun run db:migrate
-
Open production database studio
bun run db:studio
- Go to GitHub Settings β Developer settings β OAuth Apps
- Create a new OAuth App with:
- Homepage URL:
http://localhost:3000(dev) or your production URL - Authorization callback URL:
http://localhost:3000/api/auth/callback/github(dev) orhttps://your-domain.com/api/auth/callback/github(prod)
- Homepage URL:
- Copy Client ID and Client Secret to your environment variables
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials with:
- Authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(development)https://your-domain.com/api/auth/callback/google(production)
- Authorized redirect URIs:
- Copy Client ID and Client Secret to your environment variables
bun run dev # Start Next.js development server
bun run dev:wrangler # Start with Wrangler for Cloudflare compatibilitybun run db:generate # Generate migrations from schema
bun run db:migrate:local # Apply migrations to local SQLite
bun run db:migrate # Apply migrations to production D1
bun run db:studio:local # Open local database studio
bun run db:studio # Open production database studiobun run build # Build for production
bun run start # Start production server
bun run deploy # Deploy to Cloudflare Pagesbun run lint # Check code with Biome
bun run lint:fix # Fix code issues with Biome
bun run format # Format code with BiomeUsers can get API keys from:
- OpenAI: platform.openai.com/api-keys
- Anthropic: console.anthropic.com
- Google AI: ai.google.dev
- Mistral AI: console.mistral.ai
- Cohere: dashboard.cohere.ai
- OpenRouter: openrouter.ai (Access to 200+ models)
src/
βββ app/
β βββ api/
β β βββ auth/ # Authentication endpoints
β β βββ chat/ # Chat API with AI providers
β βββ auth/signin/ # Sign-in page
β βββ page.tsx # Main chat interface
βββ components/
β βββ ui/ # shadcn/ui components
β βββ chat-app.tsx # Main chat component
βββ lib/
β βββ auth.ts # NextAuth configuration
β βββ api-auth.ts # API key authentication utilities
βββ db/
β βββ drizzle/ # Database schema and utilities
βββ providers/ # React context providers
- API Key Encryption: All API keys are encrypted using AES-256-GCM before storage
- HTTP-Only Cookies: Session data stored in secure, HTTP-only cookies
- CSRF Protection: NextAuth.js provides built-in CSRF protection
- API Key Validation: Real-time validation against provider APIs
- Secure Defaults: Production-ready security settings
-
Build the application
bun run build
-
Deploy to Cloudflare Pages
bun run deploy
-
Configure environment variables in Cloudflare Pages dashboard
- Connect your repository to Vercel
- Configure environment variables in Vercel dashboard
- Deploy automatically on push to main branch
FROM node:18-alpine
WORKDIR /app
COPY package.json bun.lock ./
RUN npm install -g bun && bun install
COPY . .
RUN bun run build
EXPOSE 3000
CMD ["bun", "start"]- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Vercel AI SDK for AI integration
- NextAuth.js for authentication
- shadcn/ui for UI components
- Drizzle ORM for database management
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with β€οΈ using Next.js and the Vercel AI SDK