[Voting App] Preventing non logged in users from voting twice?

I’m nearly done with my Voting App project, but I have an issue. If a user isn’t logged in, how do I keep track of which polls they have voted on? I realize this is not a requirement, but this is something I would like to implement.

My ideas are:

  1. Set a cookie or local storage variable which stores ids of voted polls
  2. Store IPs of users voting on a poll in the poll schema in mongodb. (not something I want to do).

If anyone has implemented this feature or has any ideas, it would be great if you could share what you did/would do.

Hey, I have never done something like that. Local storage is super easy to use. Though not always available (e.g. incognito mode) and can be easily emptied. On the other hand, if anyone is seriously trying to vote several times, you will have to come up with quite an advanced system to prevent that.

I suppose it would make sense to use sessions, to at least make sure that one cannot vote multiple times in the same session. NOTE: I have never used sessions, but it seems quite easy to use.

So, if you want an easy way to prevent most of the people from voting multiple times, I would go with local storage. If you are okay with it being less sctrict, you could use sessions. You could also use a combination, so that you only need to acces local storage once per session, or use it as fallback if local storage doesn’t work.

I’ve used local storage for the React Recipe box, and sessions with the voting app. I was just wondering which would be the better approach, and I guess local storage/cookies is the way to go.

1 Like

Hello Campers! Here is my voting app https://votingking.herokuapp.com . I need someone to thoroughly test it; I’m feeling like I’ve omitted somethings out of want of time.