diff --git a/backend/email/emails/functions/helpers.tsx b/backend/email/emails/functions/helpers.tsx index 80347c0e..dfc06b65 100644 --- a/backend/email/emails/functions/helpers.tsx +++ b/backend/email/emails/functions/helpers.tsx @@ -10,6 +10,7 @@ import {render} from "@react-email/render" import {MatchesType} from "common/profiles/bookmarked_searches"; import NewSearchAlertsEmail from "email/new-search_alerts"; import WelcomeEmail from "email/welcome"; +import * as admin from "firebase-admin"; export const fromEmail = 'Compass ' @@ -82,6 +83,7 @@ export const sendWelcomeEmail = async ( privateUser: PrivateUser, ) => { if (!privateUser.email) return + const verificationLink = await admin.auth().generateEmailVerificationLink(privateUser.email); return await sendEmail({ from: fromEmail, subject: `Welcome to Compass!`, @@ -91,6 +93,7 @@ export const sendWelcomeEmail = async ( toUser={toUser} unsubscribeUrl={UNSUBSCRIBE_URL} email={privateUser.email} + verificationLink={verificationLink} /> ), }) diff --git a/backend/email/emails/welcome.tsx b/backend/email/emails/welcome.tsx index 6f546143..b231e33d 100644 --- a/backend/email/emails/welcome.tsx +++ b/backend/email/emails/welcome.tsx @@ -4,27 +4,33 @@ import {type User} from 'common/user' import {mockUser,} from './functions/mock' import {button, container, content, Footer, main, paragraph} from "email/utils"; -function randomHex(length: number) { - const bytes = new Uint8Array(Math.ceil(length / 2)); - crypto.getRandomValues(bytes); - return Array.from(bytes, b => b.toString(16).padStart(2, "0")) - .join("") - .slice(0, length); -} +// function randomHex(length: number) { +// const bytes = new Uint8Array(Math.ceil(length / 2)); +// crypto.getRandomValues(bytes); +// return Array.from(bytes, b => b.toString(16).padStart(2, "0")) +// .join("") +// .slice(0, length); +// } interface WelcomeEmailProps { toUser: User unsubscribeUrl: string email?: string + verificationLink?: string } export const WelcomeEmail = ({ toUser, unsubscribeUrl, email, + verificationLink, }: WelcomeEmailProps) => { const name = toUser.name.split(' ')[0] - const confirmUrl = `https://compassmeet.com/confirm-email/${randomHex(16)}` + + // Some users may already have a verified email (e.g., signed it with Googl), but we send them a link anyway so that + // their email provider marks Compass as spam-free once they click the link. + // We can remove the verif link for them if we ask the user to click on another link in the email (which would not be related to email verification) + // const verificationLink = `https://compassmeet.com/confirm-email/${randomHex(16)}` return ( @@ -49,14 +55,14 @@ export const WelcomeEmail = ({ Or copy and paste this link into your browser:
- {confirmUrl} + {verificationLink}