A Next.js web application that allows users to sign in with Google Auth, save their favorite movie, and discover interesting facts about it using OpenAI's API.
- π Google Authentication - Secure sign-in using Google OAuth
- π€ User Profile - Display user's name, email, and profile photo
- π¬ Favorite Movie Storage - Save and manage your favorite movie
- π€ AI-Powered Facts - Generate interesting facts about your favorite movie using OpenAI
- π Dynamic Content - Get new facts every time you refresh or request
- π¨ Modern UI - Beautiful, responsive design with Tailwind CSS
- ποΈ Database Integration - PostgreSQL with Prisma ORM
- Frontend: Next.js 14, React 18, TypeScript
- Styling: Tailwind CSS
- Authentication: NextAuth.js with Google Provider
- Database: PostgreSQL
- ORM: Prisma
- AI: OpenAI GPT-3.5-turbo
- Deployment: Ready for Vercel/Netlify
Before running this application, you need:
- Node.js (v18 or higher)
- PostgreSQL database
- Google OAuth credentials
- OpenAI API key
git clone <repository-url>
cd movie-facts-app
npm installCopy the example environment file and configure your variables:
cp env.example .env.localEdit .env.local with your actual values:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/movie_facts_db"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-nextauth-secret-key-here"
# Google OAuth
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# OpenAI
OPENAI_API_KEY="your-openai-api-key"- Install PostgreSQL on your machine
- Create a new database:
createdb movie_facts_db - Update the DATABASE_URL in your
.env.local
Use a service like:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Google+ API
- Go to "Credentials" β "Create Credentials" β "OAuth 2.0 Client IDs"
- Set application type to "Web application"
- Add authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(for development)https://yourdomain.com/api/auth/callback/google(for production)
- Copy the Client ID and Client Secret to your
.env.local
- Go to OpenAI Platform
- Create an account and get your API key
- Add the API key to your
.env.local
Generate and push the database schema:
npx prisma generate
npx prisma db pushnpm run devThe application will be available at http://localhost:3000
- Sign In: Click "Sign in with Google" to authenticate
- Set Favorite Movie: First-time users will be prompted to enter their favorite movie
- View Facts: Once logged in, you'll see interesting facts about your favorite movie
- Refresh Facts: Click "New Fact" to get a different interesting fact
- Logout: Use the logout button to sign out
βββ app/ # Next.js 13+ app directory
β βββ api/ # API routes
β β βββ auth/ # NextAuth configuration
β β βββ movie-fact/ # OpenAI integration
β β βββ user/ # User data management
β βββ dashboard/ # Main dashboard page
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
β βββ providers/ # Context providers
βββ components/ # React components
βββ lib/ # Utility libraries
βββ prisma/ # Database schema
βββ types/ # TypeScript declarations
βββ public/ # Static assets
GET /api/user/favorite-movie- Get user's favorite moviePOST /api/user/favorite-movie- Save user's favorite moviePOST /api/movie-fact- Generate movie fact using OpenAI
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpx prisma studio- Open Prisma Studio for database management
# Generate Prisma client
npx prisma generate
# Push schema changes to database
npx prisma db push
# Open Prisma Studio (database GUI)
npx prisma studio- Push your code to GitHub
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy!
The app can be deployed to any platform that supports Next.js:
- Netlify
- Railway
- DigitalOcean App Platform
- AWS Amplify
- Database Connection: Ensure your DATABASE_URL is correct and the database is accessible
- Google OAuth: Verify redirect URIs match your deployment URL
- OpenAI API: Check your API key and billing status
- Environment Variables: Ensure all required variables are set in production
If you encounter issues:
- Check the browser console for errors
- Verify all environment variables are set correctly
- Ensure the database is running and accessible
- Check that all API keys are valid
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source and available under the MIT License.