Skip to content

Commit d9927fe

Browse files
authored
Merge pull request #1832 from Mephistic/use-profile-email
Use Profile Email Instead of Firebase Auth
2 parents 8ccad85 + a285a21 commit d9927fe

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 20 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`
@@ -223,6 +232,7 @@ const renderToHtmlString = (digestData: NotificationEmailDigest) => {
223232
// Firebase Functions
224233
export const deliverNotifications = functions.pubsub
225234
.schedule("47 9 1 * 2") // 9:47 AM on the first day of the month and on Tuesdays
235+
.timeZone("America/New_York")
226236
.onRun(deliverEmailNotifications)
227237

228238
export const httpsDeliverNotifications = functions.https.onRequest(

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)