Skip to content

amitesh-maurya/poll-application

Repository files navigation

Poll Application

A full-stack poll application built with Next.js, NextAuth, and Supabase. Users can create polls, vote on them, and view real-time results with proper authentication and authorization.

🌐 Live Demo

Deployed on Vercel: Comming Soon

🚀 Quick Deploy to Vercel

One-Click Deploy (Production Ready)

Deploy with Vercel

📖 For detailed deployment instructions: See PRODUCTION_DEPLOYMENT.md

Manual Deployment Steps

  1. Fork/Clone this repository

  2. Connect to Vercel:

    • Go to vercel.com
    • Sign in with your GitHub account
    • Click "New Project"
    • Import your poll-application repository
  3. Configure Environment Variables in Vercel: Go to your project settings in Vercel and add these environment variables:

    NEXT_PUBLIC_SUPABASE_URL=https://lymdzzecuwprowhuvnku.supabase.co
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_actual_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_actual_service_role_key
    NEXTAUTH_URL=https://your-vercel-url.vercel.app
    NEXTAUTH_SECRET=your_random_secret_key_32_chars_min
    ALLOW_UNCONFIRMED_EMAIL=false
  4. Apply Database Schema:

    • Run the SQL from database-schema.sql in your Supabase SQL editor
  5. Deploy: Vercel will automatically build and deploy your application!

🛠️ Local Development

Prerequisites

  • Node.js 18+ installed
  • A Supabase account and project

Setup Instructions

  1. Clone and install dependencies:
git clone https://github.com/amitesh-maurya/poll-application.git
cd poll-application
npm install
  1. Set up your Supabase project:

    • Go to https://app.supabase.com
    • Create a new project or use an existing project
    • Navigate to Settings > API
    • Copy your project URL and API keys
  2. Configure environment variables: Create a .env.local file in the root directory:

    NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
    NEXTAUTH_URL=http://localhost:3000
    NEXTAUTH_SECRET=your_secret_key_for_local_dev
  3. Set up the database schema: Run the SQL commands from database-schema.sql in your Supabase SQL editor.

  4. Start the development server:

npm run dev

Visit http://localhost:3000 and start creating polls!

Features

  • Authentication: Secure user authentication using NextAuth with Supabase backend
  • Poll Management: Create, edit, and delete polls with multiple options
  • Voting System: One vote per user per poll with backend enforcement
  • Real-time Results: View poll results with vote counts and percentages
  • Responsive Design: Mobile-friendly interface built with Tailwind CSS
  • Route Protection: Protected routes for authenticated users only

Tech Stack

  • Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
  • Backend: Next.js API Routes, Supabase (PostgreSQL)
  • Authentication: NextAuth.js with Supabase adapter
  • Database: Supabase (PostgreSQL with Row Level Security)
  • Styling: Tailwind CSS
  • Form Handling: React Hook Form with Zod validation
  • Icons: Lucide React

Database Schema

The application uses 4 main tables:

  1. profiles - User profile information
  2. polls - Poll data with title, description, creator
  3. poll_options - Individual options for each poll
  4. votes - User votes with unique constraint per poll

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Supabase account

Setup Instructions

Option 1: Demo Mode (Recommended for Testing)

  1. Clone and Install:
git clone https://github.com/amitesh-maurya/poll-application.git
cd poll-application
npm install
npm run dev
  1. Start Using: Visit http://localhost:3001 and sign in with any email/password!

Option 2: Production Mode with Supabase

For production use with persistent data:

1. Clone the Repository

git clone https://github.com/amitesh-maurya/poll-application.git
cd poll-application

2. Install Dependencies

npm install

3. Set up Supabase

  1. Create a new project at supabase.com
  2. Go to Settings > Database and find your connection details
  3. Go to Settings > API and find your URL and anon key
  4. Go to Settings > API and find your service role key
  5. In the SQL Editor, run the contents of database-schema.sql to create tables and policies

4. Environment Variables

Create a .env.local file in the root directory:

# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key

# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your_random_secret_string

# Email Configuration (optional - for email provider)
EMAIL_SERVER_HOST=smtp.example.com
EMAIL_SERVER_PORT=587
EMAIL_SERVER_USER=your_email_user
EMAIL_SERVER_PASSWORD=your_email_password
EMAIL_FROM=noreply@example.com

5. Generate NextAuth Secret

npx auth secret

Copy the generated secret to your .env.local file.

6. Run the Application

npm run dev

The application will be available at http://localhost:3000

Usage

  1. Sign Up/Sign In: Create an account or sign in with existing credentials
  2. Dashboard: View all polls and your created polls
  3. Create Poll: Click "Create Poll" to make a new poll with multiple options
  4. Vote: Click on any poll to view details and vote (if you haven't already)
  5. View Results: After voting, see real-time results with percentages
  6. Manage Polls: Edit or delete your own polls from the dashboard

Authentication

The application uses NextAuth.js with two providers:

  • Credentials Provider: Simple email/password authentication with automatic user profile creation
  • Email Provider: Magic link authentication (requires email configuration)

User profiles are automatically created in the Supabase database when users sign in with credentials. All routes except authentication pages are protected and require login.

Database Security

  • Row Level Security (RLS) is enabled on all tables
  • Users can only see and modify their own data where appropriate
  • Votes are enforced at the database level with unique constraints
  • All API endpoints validate user permissions

API Endpoints

  • GET /api/polls - Fetch all polls or user's polls
  • POST /api/polls - Create a new poll
  • GET /api/polls/[id] - Get poll details with options and user's vote
  • PUT /api/polls/[id] - Update a poll (owner only)
  • DELETE /api/polls/[id] - Soft delete a poll (owner only)
  • POST /api/votes - Submit a vote for a poll

Development Notes

AI Tool Usage

During development, I used GitHub Copilot and Claude AI to:

  • Generate boilerplate code for API routes and components
  • Debug TypeScript type issues
  • Create a comprehensive database schema with proper relationships
  • Optimise SQL queries and database policies
  • Generate consistent styling with Tailwind CSS classes

Architecture Decisions

  1. NextAuth with Custom Implementation: Used NextAuth for session management, but implemented custom user creation in Supabase
  2. API Routes: Used Next.js API routes for backend logic rather than direct Supabase calls
  3. TypeScript: Full TypeScript implementation for type safety
  4. Tailwind CSS: Utility-first CSS for rapid UI development
  5. Simplified RLS: Database-level security with simplified policies for demo purposes

Production Deployment

For production deployment:

  1. Set up production Supabase project
  2. Configure environment variables on your hosting platform
  3. Set up a proper email provider for magic links
  4. Consider adding Google/GitHub OAuth providers
  5. Enable Supabase RLS policies
  6. Set up proper error monitoring

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

💫 Credits & Ownership

This chat application was designed and developed by Amitesh Maurya.

© 2025 Amitesh Maurya — All rights reserved.
This project is shared publicly for portfolio and learning purposes only.
Unauthorised commercial use or redistribution is strictly prohibited.

About

A full-stack poll application built with Next.js, NextAuth, and Supabase. Users can create polls, vote on them, and view real-time results with proper authentication and authorization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors