A full-stack polling application built with Next.js and Supabase that allows users to create, share, and vote on polls.
This project is a web application designed to provide a seamless experience for creating and managing polls. Registered users can create custom polls, which can then be shared via a unique link. Other users (both authenticated and anonymous, depending on the poll's settings) can then vote on these polls.
The primary goal is to build a secure, scalable, and user-friendly platform for gathering opinions.
- User Authentication: Secure sign-up and sign-in functionality using Supabase Auth.
- Poll Creation: Authenticated users can create polls with custom titles, questions, and multiple options.
- Poll Management: Users can edit or delete the polls they have created.
- Voting System: Users can vote on polls. The system prevents duplicate votes from authenticated users.
- Configurable Polls: Poll creators can configure settings such as requiring authentication to vote or setting an end date.
Follow these instructions to get the project up and running on your local machine for development and testing purposes.
-
Clone the repository:
git clone https://github.com/your-username/polling-app.git cd polling-app
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env.local
file in the root of the project by copying the example file:cp .env.example .env.local
Next, fill in the required values in
.env.local
. You can find these keys in your Supabase project's API settings.NEXT_PUBLIC_SUPABASE_URL
: Your Supabase project URL.NEXT_PUBLIC_SUPABASE_ANON_KEY
: Your Supabase project's publicanon
key.SUPABASE_SECRET_KEY
: Your Supabase project's secretservice_role
key.
-
Run the database migrations (if applicable): If you are setting up a new Supabase project, you will need to run the SQL migrations located in the
supabase/migrations
directory in the Supabase SQL Editor.
Once the installation is complete, you can run the development server:
npm run dev
Open http://localhost:3000 with your browser to see the result.
Once the application is running, you can perform the following actions:
-
Create an Account:
- Navigate to the "Sign Up" page from the header.
- Register a new account with your email and a password.
-
Create a Poll:
- After signing in, you will be redirected to the main polls page.
- Click the "Create Poll" button.
- Fill in the "Basic Info" tab with a title, question, and at least two options.
- (Optional) Switch to the "Settings" tab to require authentication for voters or set an end date.
- Click "Create Poll" to submit. You will be redirected to your new poll's page.
-
Vote on a Poll:
- From the main polls page, click on any poll to view it.
- Select one of the options.
- Click "Submit Vote". If the poll creator required authentication, you must be logged in to vote.
This project uses Vitest for unit and integration testing. To run the test suite, use the following command:
npm run test
The codebase is organized following Next.js App Router conventions:
/app
: Contains all the routes and pages for the application./components
: Houses reusable React components./components/ui
:shadcn/ui
components./components/auth
: Components related to authentication./components/polls
: Components for poll creation, voting, etc.
/lib
: Core application logic, server actions, and Supabase client setup./lib/actions
: Server Actions for data mutations (creating polls, voting)./lib/supabase
: Supabase client configurations.
/supabase/migrations
: Contains the SQL schema for the database.