Skip to content

Commit bc200d9

Browse files
committed
fix: only send email notifications to verified email addresses to help prevent spam
1 parent a235271 commit bc200d9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
UserDigest
1414
} from "../email/types"
1515
import { prepareHandlebars } from "../email/handlebarsHelpers"
16+
import { getAuth } from "firebase-admin/auth"
1617

1718
const NUM_BILLS_TO_DISPLAY = 4
1819
const NUM_USERS_TO_DISPLAY = 4
@@ -21,8 +22,14 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2122

2223
// Get a reference to the Firestore database
2324
const db = admin.firestore()
25+
const auth = getAuth()
2426
const path = require("path")
2527

28+
const isEmailVerified = async (uid: string) => {
29+
const userRecord = await auth.getUser(uid)
30+
return userRecord && userRecord.emailVerified
31+
}
32+
2633
// TODO: Batching (at both user + email level)?
2734
// Going to wait until we have a better idea of the performance impact
2835
const deliverEmailNotifications = async () => {
@@ -39,6 +46,13 @@ const deliverEmailNotifications = async () => {
3946

4047
const emailPromises = usersSnapshot.docs.map(async userDoc => {
4148
const user = userDoc.data() as User
49+
50+
const emailVerified = await isEmailVerified(userDoc.id)
51+
if (!emailVerified) {
52+
console.log(`Skipping user ${userDoc.id} because email is not verified`)
53+
return
54+
}
55+
4256
const digestData = await buildDigestData(user, userDoc.id, now)
4357

4458
// If there are no new notifications, don't send an email

0 commit comments

Comments
 (0)