Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add otp functions #265

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

feat: add otp functions #265

wants to merge 37 commits into from

Conversation

esaminu
Copy link
Collaborator

@esaminu esaminu commented Jul 17, 2024

This PR adds otp cloud functions to be called instead of using firebase email links

image image

Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fast-auth-signer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 6:45pm

@esaminu esaminu changed the title feat: add cloud functions feat: add otp functions Jul 17, 2024
@esaminu esaminu marked this pull request as ready for review July 30, 2024 19:58
@esaminu esaminu marked this pull request as draft July 30, 2024 19:58
@esaminu esaminu marked this pull request as ready for review July 30, 2024 20:44
const otp = crypto.randomInt(100000, 999999).toString();

const otpDoc = admin.firestore().collection('otps').doc(email);
await otpDoc.set({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an enhancement, could we add a check to see if there is an existing non-expired OTP for the same email before creating a new one? This would help prevent flooding the otps collection with multiple OTP requests and ensure that old OTPs are not left without cleanup.

Copy link
Collaborator Author

@esaminu esaminu Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be some issue with the email receiver that caused it to not receive the previous otp causing the user to click resend. I don't think it's good practice to re use the same code in these cases. Only one OTP code is stored at a time and every time the user clicks "Resend" we overwrite that

packages/functions/src/index.ts Outdated Show resolved Hide resolved
packages/functions/src/index.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a cron job to clean up old OTPs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old otps that are left in our db will happen when someone requests codes to multiple emails and does not verify any of them. We create one record per email (we override the record for multiple requests to the same email) and we delete the record once the user is verified and gets a token. We can add a daily cron job to handle expired otps older than a month or so IMO but they serve as a log for people trying to login and unable to get access, we can inspect the db and verify that we sent them a code - we did something similar for wallet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about the expired ones. But it makes sense to leave it there for logging purpose.

@Pessina
Copy link
Collaborator

Pessina commented Aug 8, 2024

Great improvement!!! @esaminu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants