Skip to content

Commit e52c589

Browse files
committed
fix(notifications): Re-enabling verifiedEmail fetch wrapped in try/catch for better debugging in the deployed environments. This will fall back to the current email behavior if the fetch fails (as we expect), so it should be safe.
1 parent eda777c commit e52c589

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as functions from "firebase-functions"
22
import * as handlebars from "handlebars"
33
import * as fs from "fs"
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
4+
import { auth, db, Timestamp } from "../firebase"
65
import {
76
convertHtmlToText,
87
getNextDigestAt,
@@ -26,15 +25,20 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2625

2726
const path = require("path")
2827

29-
// Temporarily using email from the profile to test the non-auth issues
30-
// const getVerifiedUserEmail = async (uid: string) => {
31-
// const userRecord = await auth.getUser(uid)
32-
// if (userRecord && userRecord.email && userRecord.emailVerified) {
33-
// return userRecord.email
34-
// } else {
35-
// return null
36-
// }
37-
// }
28+
const getVerifiedUserEmail = async (uid: string) => {
29+
// TODO: Try/catch is temporarily while troubleshooting the auth issue
30+
try {
31+
const userRecord = await auth.getUser(uid)
32+
if (userRecord && userRecord.email && userRecord.emailVerified) {
33+
return userRecord.email
34+
} else {
35+
return null
36+
}
37+
} catch (error) {
38+
console.error(`Error getting user email for UID ${uid}:`, error)
39+
return null
40+
}
41+
}
3842

3943
// TODO: Batching (at both user + email level)?
4044
// Going to wait until we have a better idea of the performance impact
@@ -65,8 +69,11 @@ const deliverEmailNotifications = async () => {
6569
return
6670
}
6771

68-
// Temporarily using email from the profile to test the non-auth issues
69-
const verifiedEmail = profile.email || profile.contactInfo?.publicEmail //await getVerifiedUserEmail(profileDoc.id)
72+
// TODO: Temporarily using email from the profile to test the non-auth issues
73+
// Should only use email from `auth` once that's working
74+
const defaultEmail = profile.email || profile.contactInfo?.publicEmail
75+
const verifiedEmail =
76+
(await getVerifiedUserEmail(profileDoc.id)) || defaultEmail
7077
if (!verifiedEmail) {
7178
console.log(
7279
`Skipping user ${profileDoc.id} because they have no verified email address`

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

0 commit comments

Comments
 (0)