added catch to the get user snapshot

This commit is contained in:
Jack 2020-08-24 16:23:27 +01:00
parent 8ec7a3070f
commit 8f30b1b09f

View file

@ -223,73 +223,78 @@ firebase.auth().onAuthStateChanged(function (user) {
}
updateAccountLoginButton();
accountIconLoading(true);
db_getUserSnapshot().then((e) => {
if (!configChangedBeforeDb) {
if (cookieConfig === null) {
accountIconLoading(false);
applyConfig(dbSnapshot.config);
// showNotification('Applying db config',3000);
updateSettingsPage();
saveConfigToCookie(true);
} else if (dbSnapshot.config !== undefined) {
let configsDifferent = false;
Object.keys(config).forEach((key) => {
if (!configsDifferent) {
try {
if (key !== "resultFilters") {
if (Array.isArray(config[key])) {
config[key].forEach((arrval, index) => {
if (arrval != dbSnapshot.config[key][index])
configsDifferent = true;
});
} else {
if (config[key] != dbSnapshot.config[key])
configsDifferent = true;
}
}
} catch (e) {
console.log(e);
configsDifferent = true;
}
}
});
if (configsDifferent) {
db_getUserSnapshot()
.then((e) => {
if (!configChangedBeforeDb) {
if (cookieConfig === null) {
accountIconLoading(false);
applyConfig(dbSnapshot.config);
// showNotification('Applying db config',3000);
updateSettingsPage();
saveConfigToCookie(true);
} else if (dbSnapshot.config !== undefined) {
let configsDifferent = false;
Object.keys(config).forEach((key) => {
if (!configsDifferent) {
try {
if (key !== "resultFilters") {
if (Array.isArray(config[key])) {
config[key].forEach((arrval, index) => {
if (arrval != dbSnapshot.config[key][index])
configsDifferent = true;
});
} else {
if (config[key] != dbSnapshot.config[key])
configsDifferent = true;
}
}
} catch (e) {
console.log(e);
configsDifferent = true;
}
}
});
if (configsDifferent) {
accountIconLoading(false);
applyConfig(dbSnapshot.config);
updateSettingsPage();
saveConfigToCookie(true);
}
}
dbConfigLoaded = true;
} else {
accountIconLoading(false);
}
if (
config.resultFilters === undefined ||
config.resultFilters === null ||
config.resultFilters.difficulty === undefined
) {
if (
dbSnapshot.config.resultFilters == null ||
dbSnapshot.config.resultFilters.difficulty === undefined
) {
config.resultFilters = defaultAccountFilters;
} else {
config.resultFilters = dbSnapshot.config.resultFilters;
}
}
dbConfigLoaded = true;
} else {
accountIconLoading(false);
}
if (
config.resultFilters === undefined ||
config.resultFilters === null ||
config.resultFilters.difficulty === undefined
) {
if (
dbSnapshot.config.resultFilters == null ||
dbSnapshot.config.resultFilters.difficulty === undefined
) {
config.resultFilters = defaultAccountFilters;
} else {
config.resultFilters = dbSnapshot.config.resultFilters;
if ($(".pageLogin").hasClass("active")) {
changePage("account");
}
}
if ($(".pageLogin").hasClass("active")) {
changePage("account");
}
refreshThemeButtons();
accountIconLoading(false);
updateFilterTags();
updateCommandsTagsList();
loadActiveTagsFromCookie();
updateResultEditTagsPanelButtons();
refreshTagsSettingsSection();
updateDiscordSettingsSection();
});
refreshThemeButtons();
accountIconLoading(false);
updateFilterTags();
updateCommandsTagsList();
loadActiveTagsFromCookie();
updateResultEditTagsPanelButtons();
refreshTagsSettingsSection();
updateDiscordSettingsSection();
})
.catch((e) => {
accountIconLoading(false);
showNotification("Error donwloading user data: " + e, 5000);
});
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;