11import * as functions from "firebase-functions"
22import * as handlebars from "handlebars"
33import * 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"
65import {
76 convertHtmlToText ,
87 getNextDigestAt ,
@@ -26,15 +25,20 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2625
2726const 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`
0 commit comments