/** * Phone-first signup still has to put something in `users.email` — better-auth * requires it to be present and unique. We mint a synthetic address on a domain * we control and never deliver to. * * For a plumber-and-electrician marketplace this will be MOST client accounts, * so every outbound-mail path must check `isSyntheticEmail` first. Sending to * one is not merely useless: it is a bounce against our sending reputation, and * at volume that costs us delivery to the addresses that are real. * * Pros are required to supply a genuine address during onboarding — they need * payout statements, tax records and dispute notices. Clients may never have one * and are served over SMS instead. */ export const SYNTHETIC_EMAIL_DOMAIN = 'phone.linkder.local'; export function syntheticEmailFor(phoneE164: string): string { return `${phoneE164}@${SYNTHETIC_EMAIL_DOMAIN}`; } export function isSyntheticEmail(email: string | null | undefined): boolean { if (!email) return true; // nothing to send to is, for our purposes, the same thing return email.toLowerCase().endsWith(`@${SYNTHETIC_EMAIL_DOMAIN}`); } /** True when we can actually put a message in front of this person by email. */ export function isContactableEmail(email: string | null | undefined): email is string { return !isSyntheticEmail(email); } /** * Recover the phone number a synthetic address was minted from. * Useful in support tooling; returns null for a real address. */ export function phoneFromSyntheticEmail(email: string): string | null { if (!isSyntheticEmail(email)) return null; const [local] = email.split('@'); return local && local.startsWith('+') ? local : null; }