Fallback behavior for case-sensitivity issues in email lookup (#4188)

This commit is contained in:
Robert Helmer 2024-02-09 13:23:21 -08:00 коммит произвёл GitHub
Родитель 23b446bf64
Коммит ccb9146c09
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -5,6 +5,7 @@
import { Session } from "next-auth";
import { getSubscriberByEmail } from "../../../db/tables/subscribers.js";
import { getUserEmails } from "../../../db/tables/emailAddresses.js";
import { logger } from "./logging.js";
/**
* NOTE: new function to replace getUserBreaches
@ -15,7 +16,21 @@ export async function getSubscriberEmails(
user: Session["user"],
): Promise<string[]> {
const emailArray: string[] = [user.email];
const subscriber = await getSubscriberByEmail(user.email);
// FIXME case-insensitivity issues, fallback to previous behavior https://mozilla-hub.atlassian.net/browse/MNTOR-2936
const email = user.subscriber?.fxa_profile_json?.email;
let subscriber;
if (email) {
subscriber = await getSubscriberByEmail(email);
}
if (!subscriber?.id) {
logger.warn("fallback_subscriber_email", { user });
subscriber = await getSubscriberByEmail(user.email);
}
if (!subscriber?.id) {
logger.error("no_subscriber_for_email", { user });
throw new Error("no subscriber ID for email");
}
(await getUserEmails(subscriber.id)).forEach((e) => emailArray.push(e.email));
return emailArray;
}