in javascript/widgets/config.js [532:597]
getPhoneAuthAvailableCountries() {
const signInOptions = this.getSignInOptionsForProvider_(
firebase.auth.PhoneAuthProvider.PROVIDER_ID);
if (!signInOptions) {
return null;
}
const whitelistedCountries = signInOptions['whitelistedCountries'];
const blacklistedCountries = signInOptions['blacklistedCountries'];
// First validate the input.
if (typeof whitelistedCountries !== 'undefined' &&
(!Array.isArray(whitelistedCountries) ||
whitelistedCountries.length == 0)) {
throw new Error('WhitelistedCountries must be a non-empty array.');
}
if (typeof blacklistedCountries !== 'undefined' &&
(!Array.isArray(blacklistedCountries))) {
throw new Error('BlacklistedCountries must be an array.');
}
// If both allowlist and disallowlist are provided, throw error.
if (whitelistedCountries && blacklistedCountries) {
throw new Error(
'Both whitelistedCountries and blacklistedCountries are provided.');
}
// If no allowlist or disallowlist provided, return all available countries.
if (!whitelistedCountries && !blacklistedCountries) {
return country.COUNTRY_LIST;
}
let countries = [];
const availableCountries = [];
if (whitelistedCountries) {
// Allowlist is provided.
const whitelistedCountryMap = {};
for (let i = 0; i < whitelistedCountries.length; i++) {
countries = country
.getCountriesByE164OrIsoCode(whitelistedCountries[i]);
// Remove duplicate and overlaps by putting into a map.
for (let j = 0; j < countries.length; j++) {
whitelistedCountryMap[countries[j].e164_key] = countries[j];
}
}
for (let countryKey in whitelistedCountryMap) {
if (whitelistedCountryMap.hasOwnProperty(countryKey)) {
availableCountries.push(whitelistedCountryMap[countryKey]);
}
}
return availableCountries;
} else {
const blacklistedCountryMap = {};
for (let i = 0; i < blacklistedCountries.length; i++) {
countries = country
.getCountriesByE164OrIsoCode(blacklistedCountries[i]);
// Remove duplicate and overlaps by putting into a map.
for (let j = 0; j < countries.length; j++) {
blacklistedCountryMap[countries[j].e164_key] = countries[j];
}
}
for (let k = 0; k < country.COUNTRY_LIST.length; k++) {
if (!googObject.containsKey(
blacklistedCountryMap,
country.COUNTRY_LIST[k].e164_key)) {
availableCountries.push(country.COUNTRY_LIST[k]);
}
}
return availableCountries;
}
}