0

I am using Firesharp for my app in c# winforms. This database is also connected to my ReactJS website which deals with the same information.

I have noticed that when I make .SetAsync calls to my app on the website and then log in to my Winforms app, my WinForms app will automatically perform the last action I did on my website to my database which is a .setAsync() action which adds some user information to a list of other user's information. Now it will not stop. Anytime I log on to my c# app, it runs it.

It makes me think there is a queue of orders in firesharp?

here is my react code. From what I can tell, it is nothing out of the ordinary:

async function handleSubmit(e) {
        e.preventDefault()

        var date = moment().format("MM/DD/YYYY" )

        setError("")
        setLoading(true)

        // grab user info first then use that.
        await firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").on('value', snapshot => {
            if (snapshot.val() != null) {
                setContactObjects({
                    ...snapshot.val()
                })

                firebaseApp.database().ref("Projects/" + projectGUIDRef.current.value + "/queueList/" + userIdRef.current.value).set({
                    "EntryTimeStamp": date + " " + moment().format("hh:mm:ss a"),
                    "IsSyncing": false,
                    "UserId": userIdRef.current.value,
                    "UserName": usernameRef.current.value,
                })
            }
        })

        history.push("/Demo")

        setLoading(false)
    }

here is my c# winforms code of where the code is executing. For some reason, when this executes, it also updates the EntryTimeStamp field of the react code and completely sets all the information even if I delete it. It also happens if I run .set().

updateLastLogin2(authLink);

private async void updateLastLogin2(FirebaseAuthLink authLink)
        {
            IFirebaseConfig config = new FireSharp.Config.FirebaseConfig
            {
                AuthSecret = this.authLink.FirebaseToken,
                BasePath = Command.dbURL,
            };
            IFirebaseClient client = new FireSharp.FirebaseClient(config);

            string newDateTime = DateTime.Now.ToString();

            if (authLink.User.DisplayName.Contains(adUserId) && authLink.User.DisplayName.Contains(adUserId))
            {
                await client.SetAsync("Users/" + this.authLink.User.LocalId + "/UserData/DateLastLogin", newDateTime);
            }
        }

Any and all help is appreciated, I've been at this for a day and a half now.

Cflux
  • 1,423
  • 3
  • 19
  • 39

1 Answers1

0

I have never used fire-sharp but this is my guess

You are calling await firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").on('value' in your react, and then in your Csharp you are calling client.SetAsync("Users/" + this.authLink.User.LocalId .

What happens is the both listeners are listening to each other and then causing a loop.

In that case it's probably better to use once instead of on if you are just using it once.

In cases where you cannot use .once, then you should use .off to turn off the listener once you are done.

firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").once('value'`

You also shouldn't be using await here since ref().on creates a listener, it doesn't return a promise.

You should also move history.push("/Demo") into your firebase database callback function so it's called after you have set data

Someone Special
  • 12,479
  • 7
  • 45
  • 76