1
1
import * as functions from "firebase-functions"
2
2
import * as handlebars from "handlebars"
3
3
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"
6
5
import {
7
6
convertHtmlToText ,
8
7
getNextDigestAt ,
@@ -26,15 +25,20 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
26
25
27
26
const path = require ( "path" )
28
27
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
+ }
38
42
39
43
// TODO: Batching (at both user + email level)?
40
44
// Going to wait until we have a better idea of the performance impact
@@ -65,8 +69,11 @@ const deliverEmailNotifications = async () => {
65
69
return
66
70
}
67
71
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
70
77
if ( ! verifiedEmail ) {
71
78
console . log (
72
79
`Skipping user ${ profileDoc . id } because they have no verified email address`
0 commit comments