Firebase Auth Rules and Problems

I am working on a goals app and storing with Firebase Realtime Database. Everything works fine until I close the app and open it again.
I am still logged in, but I can’t update the database through my app as I could when I first logged in.

My Firebase Rules:

{
  "rules": {
    "$user_id": {
    ".write": "$user_id === auth.uid",
".read": "$user_id === auth.uid"
    }
  }
}

Any idea what my problem is? Is it something on my end or somewhere in Thunkable or Google?

1 Like

How do you know you are still logged in to Firebase? Are there app variables you are using that should instead be stored variables so that they save their values when you re-open the app?

What do your blocks look like for Sign In?

1 Like

You have to log in every time you start the app.

I guess I don’t know. I store everything either as stored or cloud variables. I don’t tell Firebase to log out unless a button is clicked. My sign in blocks say as long as there’s not an error passed, and the email is verified, store the user ID as a stored variable, and make a stored variable isLoggedIn to true so they stay logged in from my app’s perspective until they click the log out button.

Riley Grigg

1 Like

Ok. Is there a way to log in in the background if the user hasn’t chosen to click the logout button?

1 Like

Firebase use session token to identify logged in users so whenever the user closes the app, the session token is destroyed.

One way is to use the stored user name and password and automatically log the user in next time the app is used and the IsLoggedIn is set to true. This way a new session token will be established so you can access Firebase Realtime DB.

2 Likes

Ok. Thank you!

Riley Grigg

That did it. Thanks!

Riley Grigg

2 Likes