Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

715 B
Raw Blame
import { getEmailDomainBlockFlags } from "./get-email-domain-block-flags";
import { isGenericEmail } from "./is-generic-email";

/**
 * Disposable domains are always rejected, blocked terms apply, and generic
 * current emails with + are locked.
 */
export async function canChangeEmail({
  currentEmail,
  newEmail,
}: {
  currentEmail: string;
  newEmail: string;
}): Promise<boolean> {
  const { isDisposable, matchesBlockedTerms } =
    await getEmailDomainBlockFlags(newEmail);

  if (isDisposable) {
    return false;
  }

  const isGenericEmailWithPlus =
    currentEmail.includes("+") && isGenericEmail(currentEmail);

  if (isGenericEmailWithPlus) {
    return false;
  }

  return !matchesBlockedTerms;
}