I have also worked up the getTaglist feature.
Here is the completed html which can be used for the dataChanged event. Firebase returns everything, not the individual changed/added/removed item/s, so work needs to be done when the json is received back through the webviewstring. I have the firebase js scripts stored in the assets along with the html file. All the user details and the firebase config, comes through the webviewstring.
<!DOCTYPE html>
<html>
<meta name=âviewportâ content=âwidth=device-width, initial-scale=1.0â>
<meta charset="utf-8">
<head>
<title>DataChanged</title>
<script src="firebase-app.js"></script>
<script src="firebase-auth.js"></script>
<script src="firebase-database.js"></script>
</head>
<body>
<script>
var wvstr = window.AppInventor.getWebViewString();
var email = wvstr.split(",")[0];
var pass = wvstr.split(",")[1];
var setPB = wvstr.split(",")[2];
var uid = wvstr.split(",")[3];
var firebaseConfig = {
apiKey: wvstr.split(",")[4],
authDomain: wvstr.split(",")[5],
databaseURL: wvstr.split(",")[6],
projectId: wvstr.split(",")[7],
storageBucket: wvstr.split(",")[8],
};
firebase.initializeApp(firebaseConfig);
var auth = firebase.auth();
auth.signInWithEmailAndPassword(email,pass);
auth.onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
getData();
} else {
// No user is signed in. <Use error message here>
}
});
function getData() {
var dbRefObject = firebase.database().ref().child(setPB +"/"+ uid);
dbRefObject.on('value', snap => {
window.AppInventor.setWebViewString(JSON.stringify(snap.val(), null, 3));
});
}
</script>
</body>
</html>