-
-
Notifications
You must be signed in to change notification settings - Fork 162
Description
I was just exploring the authentication backend logic and i just came across a serious issue.
- Issue:
The database stores isVerified field for every user to make sure the email he entered is valid, at this step if a user gives a fake email and during the email verification using OTP if he refreshes the page without filling the OTP, his details gets save to the users collection in the database as isVerified = false. And that's totally correct, but if you try logging in with this isVerified = false id, you will still be able to login to your account.
- Major flows in this -
Even if you don't verify your account, you can still login as a user.
Database will get cluttered with fake emails.
- Steps to reproduce -
- Create a new account, during OTP submission refresh the page without filling in the OTP.
- Login with the credentials you used for the sign up.
- You'll be logged in, even the database stores you as
isVerified = false.
Changes i propose-
Opt1. For preventing the database from getting cluttered, we can save the user's details in the database after his email is verified not as he signs up.
Opt2. if isVerified = false we can add a logic in login to don't allow users where isVerified = false.
I would recommend going with the Opt1 changes as it would be a permanent solution that we pass the signed jwt token during signup and verify the decoded jwt token during the verification and then save it to the database. This will prevent cluttering of database and only saves the user when isVerified=true.
Opt2. will make things easy isVerified=false users will not be able to log in but the problem will be that they won't be able to verify their account at any moment, because the OTP option comes only after signup and we have to fill it up at the moment only.