Skip to content

Commit fd27b67

Browse files
committed
Use email from user profile instead of firebase auth for now. This is sub-optimal because we can't confirm that we've verified the email before sending, but sendgrid bounce management should cap the pain that can cause, users can't modify these message so the spam potential is severely limited, and the ongoing firebase auth credentials issue makes this check cause more pain than it resolves.
1 parent 8ccad85 commit fd27b67

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as functions from "firebase-functions"
22
import * as handlebars from "handlebars"
33
import * as fs from "fs"
4-
import { auth, db, Timestamp } from "../firebase"
4+
import { db, Timestamp } from "../firebase"
5+
//import { auth, db, Timestamp } from "../firebase" // Temporarily using email from the profile to test the non-auth issues
56
import { getNextDigestAt, getNotificationStartDate } from "./helpers"
67
import { startOfDay } from "date-fns"
78
import { TestimonySubmissionNotificationFields, Profile } from "./types"
@@ -21,14 +22,15 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2122

2223
const path = require("path")
2324

24-
const getVerifiedUserEmail = async (uid: string) => {
25-
const userRecord = await auth.getUser(uid)
26-
if (userRecord && userRecord.email && userRecord.emailVerified) {
27-
return userRecord.email
28-
} else {
29-
return null
30-
}
31-
}
25+
// Temporarily using email from the profile to test the non-auth issues
26+
// const getVerifiedUserEmail = async (uid: string) => {
27+
// const userRecord = await auth.getUser(uid)
28+
// if (userRecord && userRecord.email && userRecord.emailVerified) {
29+
// return userRecord.email
30+
// } else {
31+
// return null
32+
// }
33+
// }
3234

3335
// TODO: Batching (at both user + email level)?
3436
// Going to wait until we have a better idea of the performance impact
@@ -44,6 +46,12 @@ const deliverEmailNotifications = async () => {
4446
.where("nextDigestAt", "<=", now)
4547
.get()
4648

49+
console.log(
50+
`Processing ${
51+
profilesSnapshot.size
52+
} profiles with nextDigestAt <= ${now.toDate()}`
53+
)
54+
4755
const emailPromises = profilesSnapshot.docs.map(async profileDoc => {
4856
const profile = profileDoc.data() as Profile
4957
if (!profile || !profile.notificationFrequency) {
@@ -53,7 +61,8 @@ const deliverEmailNotifications = async () => {
5361
return
5462
}
5563

56-
const verifiedEmail = await getVerifiedUserEmail(profileDoc.id)
64+
// Temporarily using email from the profile to test the non-auth issues
65+
const verifiedEmail = profile.email //await getVerifiedUserEmail(profileDoc.id)
5766
if (!verifiedEmail) {
5867
console.log(
5968
`Skipping user ${profileDoc.id} because they have no verified email address`

functions/src/notifications/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface BillHistoryUpdateNotificationFields {
6565
}
6666

6767
export interface Profile {
68+
email?: string
6869
notificationFrequency?: Frequency
6970
nextDigestAt?: FirebaseFirestore.Timestamp
7071
}

0 commit comments

Comments
 (0)