Currently stuck in my JavaScript file, attempting to upload data but encountering a perplexing issue. It seems that myUid variable isn't updating as expected. Can anyone provide guidance on how to address this issue and shed some light on why myUid is failing to update?
var myUid = '33';
firebase.auth().signInAnonymously().catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var isAnonymous = user.isAnonymous;
window.myUid = user.uid;
// ...
} else {
// User is signed out.
// ...
}
// ...
});
function writeUserData() {
database.ref('users/').set({
profileID: myUid,
});
};
writeUserData();
Warm regards, Sam