Whenever a value in the firebase database is false, I need to shut down the app for maintenance purposes. A problem arises when the user is already logged in, as the function does not trigger unless I reload the app. I am looking for a way to trigger the function every time a user accesses a page. How can I achieve this?
Below is the TypeScript code I have been using:
checkServerStatus() {
this.afs.collection('settings').doc('PlatformStatus').ref.get().then(doc => {
let status = doc.data().statusMobileApp;
if(status){
this.nav.setRoot(HomePage);
}
else{
Swal({
type: 'info',
title: 'Database Connection Issue' ,
html: 'Error connecting to the database. Please try again later.'+
'<br><br><div class="swalButtonContainer"><button id="btnGiveOptionsAccept" type="button" role="button"" class="customSwalBtnRed">' + 'Accept' + '</button>',
showCancelButton: false,
showConfirmButton: false,
});
this.userProvider.logout();
let btn3 = document.getElementById("btnGiveOptionsAccept");
btn3.addEventListener("click", (e:Event) => {
Swal.close();
this.nav.push(LoginPage);
});
}
});
}
This function is located in the app.components file.