Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 7x 7x | // Internal helpers shared by the pro auth (`auth.ts`) and homeowner auth
// (`homeowner-auth.ts`) Better Auth instances. Lives in apps/api because
// it's tied to Better Auth's signup-by-phone flow and the temp-email schema
// — not generic enough to belong in @interioring/utils.
import { normalizeToE164 } from "@interioring/utils/validation/phone";
/**
* Build the local-part of the temp email Better Auth assigns when a user
* signs up by phone. Strips the "+" from E.164 (e.g. "+919876543210" →
* "919876543210") so the resulting email has a valid local-part.
*
* Falls back to digit-only stripping when the input is unparseable so the
* sign-up flow doesn't hard-fail on malformed input — the user's phone has
* already been validated upstream by Better Auth's OTP step.
*/
export function phoneToTempEmailLocalPart(phone: string): string {
const e164 = normalizeToE164(phone);
return e164 ? e164.slice(1) : phone.replace(/\D/g, "");
}
|