···2424} from "app/lish/subscribeToPublication";
2525import type { OAuthSessionError } from "src/atproto-oauth";
2626import { normalizePublicationRecord } from "src/utils/normalizeRecords";
2727+import { linkOrphanedEmailSubscribers } from "src/utils/linkOrphanedEmailSubscribers";
27282829type RequestError =
2930 | "invalid_email"
···367368 console.error("[subscribeEmail] attach email failed:", error);
368369 return Err("database_error");
369370 }
371371+ await linkOrphanedEmailSubscribers(current.id, email);
370372 await backfillAtprotoSubscriptionsForIdentity(current.id, current.atp_did);
371373 return Ok(current.id);
372374 }
···397399 console.error("[subscribeEmail] identity upsert failed:", identityError);
398400 return null;
399401 }
402402+403403+ // Cover any sibling subscriber rows (e.g. CSV-imported entries on other
404404+ // publications) so this confirmation also adopts them under the new identity.
405405+ await linkOrphanedEmailSubscribers(identity.id, email);
400406401407 const { data: token, error: tokenError } = await supabaseServerClient
402408 .from("email_auth_tokens")
+25
src/utils/linkOrphanedEmailSubscribers.ts
···11+import { supabaseServerClient } from "supabase/serverClient";
22+33+// Link any pre-existing email-subscriber rows for `email` to `identityId` if
44+// they're not already linked. Call this whenever an identity newly comes to
55+// own an email so that imported / pre-confirmation-flow subscribers become
66+// visible to their owner. Idempotent — safe to call on every signup/login.
77+export async function linkOrphanedEmailSubscribers(
88+ identityId: string,
99+ email: string,
1010+) {
1111+ const normalized = email.trim().toLowerCase();
1212+ if (!normalized) return;
1313+ const { error } = await supabaseServerClient
1414+ .from("publication_email_subscribers")
1515+ .update({ identity_id: identityId })
1616+ .eq("email", normalized)
1717+ .is("identity_id", null);
1818+ if (error) {
1919+ console.error(
2020+ "[linkOrphanedEmailSubscribers] failed:",
2121+ error.message,
2222+ { identityId, email: normalized },
2323+ );
2424+ }
2525+}