Skip to content

A platform where users can create polls and everyone can vote in them. It uses a MongoDB Atlas database to store users and polls.

License

Notifications You must be signed in to change notification settings

SSbit01/voting-app

Repository files navigation

Voting App

This is a Next.js platform created by SSbit01 where users can create polls and everyone can vote in them. It uses a MongoDB Atlas database to store users and polls.

NOTE

This platform has many security vulnerabilities. This is just a simple personal project that was made a long time ago. Please use it for simple tasks. Go to vulnerabilities.


Required environment variables

  • MONGO_URI : MongoDB URI string
  • COOKIE_NAME : e.g. voting-app_cookie
  • COOKIE_PASSWORD : complex password at least 32 characters long

Remember to install local packages, I used pnpm package manager in this project, but of course you can use any other package manager like npm or yarn.


This project works like any other Next.js project. The following scripts can be found in the package.json file and refer to the different development stages.

"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"

Vulnerabilities

  • User ID is exposed to the client.

Known issues

  • The user name is stored in the cookie but it doesn't get updated if another session changes it.

To Do

  • GLOBAL
    • Solve the vulnerabilities and known issues
    • Hash the password on the client side and send the result to the server to verify it. Doing this the server doesn't know the user's password.
    • Try to cache SWR results in localStorage. See Persistent Cache
  • /components/Poll.tsx
    • Simplify Structure: use multiple contexts
  • /pages/api/voted.ts
    • Sort the results according to when each vote was added, not by poll id
  • /pages/api/user/[id].ts
    • Remove this path. Replace it with just /pages/api/user