@@ -13,6 +13,7 @@ import {
13
13
UserDigest
14
14
} from "../email/types"
15
15
import { prepareHandlebars } from "../email/handlebarsHelpers"
16
+ import { getAuth } from "firebase-admin/auth"
16
17
17
18
const NUM_BILLS_TO_DISPLAY = 4
18
19
const NUM_USERS_TO_DISPLAY = 4
@@ -21,8 +22,14 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
21
22
22
23
// Get a reference to the Firestore database
23
24
const db = admin . firestore ( )
25
+ const auth = getAuth ( )
24
26
const path = require ( "path" )
25
27
28
+ const isEmailVerified = async ( uid : string ) => {
29
+ const userRecord = await auth . getUser ( uid )
30
+ return userRecord && userRecord . emailVerified
31
+ }
32
+
26
33
// TODO: Batching (at both user + email level)?
27
34
// Going to wait until we have a better idea of the performance impact
28
35
const deliverEmailNotifications = async ( ) => {
@@ -39,6 +46,13 @@ const deliverEmailNotifications = async () => {
39
46
40
47
const emailPromises = usersSnapshot . docs . map ( async userDoc => {
41
48
const user = userDoc . data ( ) as User
49
+
50
+ const emailVerified = await isEmailVerified ( userDoc . id )
51
+ if ( ! emailVerified ) {
52
+ console . log ( `Skipping user ${ userDoc . id } because email is not verified` )
53
+ return
54
+ }
55
+
42
56
const digestData = await buildDigestData ( user , userDoc . id , now )
43
57
44
58
// If there are no new notifications, don't send an email
0 commit comments