diff --git a/backend/api/src/create-user.ts b/backend/api/src/create-user.ts index 9360a3e2..4f18fe10 100644 --- a/backend/api/src/create-user.ts +++ b/backend/api/src/create-user.ts @@ -13,6 +13,7 @@ import {createSupabaseDirectClient} from 'shared/supabase/init' import {insert} from 'shared/supabase/utils' import {convertPrivateUser, convertUser} from 'common/supabase/users' import {getBucket} from "shared/firebase-utils"; +import {sendWelcomeEmail} from "email/functions/helpers"; export const createUser: APIHandler<'create-user'> = async ( props, @@ -128,6 +129,11 @@ export const createUser: APIHandler<'create-user'> = async ( } catch (e) { console.log('Failed to track create profile', e) } + try { + await sendWelcomeEmail(user, privateUser) + } catch (e) { + console.log('Failed to sendWelcomeEmail', e) + } } return { diff --git a/backend/email/emails/functions/helpers.tsx b/backend/email/emails/functions/helpers.tsx index c042117d..3baf6505 100644 --- a/backend/email/emails/functions/helpers.tsx +++ b/backend/email/emails/functions/helpers.tsx @@ -1,5 +1,5 @@ import {PrivateUser, User} from 'common/user' -import {getNotificationDestinationsForUser} from 'common/user-notification-preferences' +import {getNotificationDestinationsForUser, UNSUBSCRIBE_URL} from 'common/user-notification-preferences' import {sendEmail} from './send-email' import {NewMessageEmail} from '../new-message' import {NewEndorsementEmail} from '../new-endorsement' @@ -8,6 +8,7 @@ import {getProfile} from 'shared/love/supabase' import { render } from "@react-email/render" import {MatchesType} from "common/love/bookmarked_searches"; import NewSearchAlertsEmail from "email/new-search_alerts"; +import WelcomeEmail from "email/welcome"; const from = 'Compass ' @@ -75,6 +76,25 @@ export const sendNewMessageEmail = async ( }) } +export const sendWelcomeEmail = async ( + toUser: User, + privateUser: PrivateUser, +) => { + if (!privateUser.email) return + return await sendEmail({ + from, + subject: `Welcome to Compass!`, + to: privateUser.email, + html: await render( + + ), + }) +} + export const sendSearchAlertsEmail = async ( toUser: User, privateUser: PrivateUser, diff --git a/backend/email/emails/welcome.tsx b/backend/email/emails/welcome.tsx index 765c72f2..83ab337a 100644 --- a/backend/email/emails/welcome.tsx +++ b/backend/email/emails/welcome.tsx @@ -3,20 +3,27 @@ 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); +} + interface WelcomeEmailProps { toUser: User unsubscribeUrl: string email?: string } -export const confirmUrl = `https://compassmeet.com/confirm-email/abc123` - export const WelcomeEmail = ({ toUser, unsubscribeUrl, email, }: WelcomeEmailProps) => { const name = toUser.name.split(' ')[0] + const confirmUrl = `https://compassmeet.com/confirm-email/${randomHex(16)}` return (