Data stops being retrieved from Firebase database after a few hours - android

I've got an Android application that uses Firebase password and email authentication and the real time database. This all works completely fine when the user has just logged in.
However maybe a few hours later data will stop being shown even if the data changes in the database, it almost seems as though the user is no longer authenticated. But when I connect my device to the adb I can see in the log that the user is logged in with the correct uid and there are no errors being reported. The only strange thing I noticed is that there is no network requests in the network monitor.
Can anyone shed some light on what is happening? I'm not sure if it's a database problem or an authentication problem. I can provide any information needed
EDIT
Marked answer down below but also take a look at these instructions also when adding your SHA1 Keys to firebase, add both production and dev copies

You need to add SHA1 of your debug and production certificates to Firebase console.
It is needed so firebase knows your app has access to refresh access token.
Docs Reference: https://firebase.google.com/support/guides/launch-checklist

Related

Multiple Accounts suddenly added in Firebase Authentication

I'm currently developing an app which is only accessible by me for now. I can already connect to Firebase but somehow I noticed that there's alot of unknown email added. I'm expecting it to have around 4 email which I have used for testing. May I know why this happened? And will this affect my app if ever I finished developing it?
Note that I didn't share/upload any info/keys that I'm using.
I was thinking that someone might have used my info/keys mistakenly that is why this happens.
If you uploaded your App to the Play Store such accounts are created by Google while they verify your app. That is normal. You don't need to worry about it.
Also see: My Firebase project has unknown users, has my google cloud service account been compromised?

Firebase unable to process request due to missing initial state

I am trying to use phone auth from firebase and I get this error now.
Unable to process request due to missing initial state. This may happen if browser session storage is inaccessible or accidentally cleared.
This was working a week ago and no longer works.
I have solved this by registering my app with SafetyNet with SHA2. To do this follow these steps:
Get your SHA2. If you don't know how to get this, follow this tutorial:
https://www.youtube.com/watch?v=kLaNnuoqnmA
Note. This youtube link is for SHA1 but you will notice that SHA2 will be shown here if you pay attention.
Go to your Firebase Console then, go to Project Settings > App Check. You will notice your app is "Unregistered." click this to register your app.
Enter the SHA2 you copied and Accept some terms below then click Save. you will notice the "Registered" with green check icon.
Btw, this error happens on one of my devices but not on another. I also searched through this error and no one has solved this including this page. This happens in my phone authentication using firebase when getting an OTP as I send my phone number. The app tries to redirect you to a browser for Recaptcha for verification if you don't have SafetyNet. Thus, having no SafetyNet will cause your app to always be redirected for Recaptcha which sometimes causes an error. Thus, to solve this, register your app with Safety Net. to understand this, read this documentation.
https://firebase.google.com/docs/auth/android/phone-auth?authuser=0
Focus on 2. Enable App Verification and you will notice that recaptcha is just an alternative for SafetyNet.
It had on the Ionic/Angular/Capacitor app too. i.e. Android and Chrome. Firebase Auth with Microsoft Login.
So I have cleared all the chrome browser data on the Android device and then no issues. i.e. working fine now.
More workarounds: https://github.com/firebase/firebase-js-sdk/issues/4256
I experienced the issue with an iphone web app. I went into Settings -> Safari and disabled 'Prevent Cross-Site Tracking'.

How to remeber users without sign up in android?

Im working on a project where a user isn´t forced to sign up a account.
My plan is that a user could do anything like a user that is registered except for a few exceptions.
I implement a like function which saves the users behaviour on a webserver and later when the data is fetched again it recognized if the user liked something or not. My problem is that I have to save this informations also if the user isn´t registered to my application. A User should be free to decide wheter the user likes to sign up or not and isn´t forced to be a registered user.
I found three different way that could work!
1. Option
First option would be the accountmanager but I don´t like this option at all cause I have to ask for the contact permission and also ask which account a user want to use.
2. Option
A other option would be if a user starts the app for the very first time the app would call a server which creates a random unique code and send that code to my application to save it as key for the users actions which is saved on a server. But that also doesn´t seems to be a good solution for my problem.
3. Option
The last option would be oauth but for now I don´t know if and how it would be the solution to my problem!
I would be thankful for every answer!
I have worked on a comic app that requires saving the user subscribed channels, genre or comics and save the likes/dislikes for the same. User can be subscribed to push notification too.
For this, we used Firebase Authentication (anonymous signup). And to save the user subscription information, we used Firebase Firestore.
And followed the below approach.
As soon as the app opens, check if the user has already anonymous SignIn. If it hasn't, signUp silently.
Add a listener for user push notification token change. And update it to Firestore by anonymous user-id as key (We did same for storing other information too).
I think this approach would help to solve this problem.
You could use firebase auth for that!
Usually, you would use it with email & password or google login but it also has an anonymous login feature that should save the user's phone.
There are few techniques. It depends on whether you want to recognise a user between installations of app. If you are OK to lose a user on reinstallation you can use Firebase installation ID and link users behaviour with this id. If you want to remember users even between installations you can use unique to each combination of app-signing key, user, and device Secure.ANDROID_ID(more info about ids). But still the best way is implementing your own signing in or using of AccountManager.

Persisting anonymous credentials after uninstall firebase - Android

I can not figure out if this should work or not.
According to this post it should NOT work. But it's also from 2017.
According to this it should be stored in the Keystore services, which seems to only be erased if you log out.
Played a couple of other games that I'm confident uses firebase as well, and they seem to be able to log me back in after I uninstall the app (without connecting to Facebook or similar)
Also as a side note iOS keeps the credentials also after uninstall and are able to log back in

Google Login with Firebase Auth returning an error

I opted to go with Firebase Auth for my app and it's generally pretty straightforward. I changed Google accounts early in the development because I wanted to keep these two separate, and I suspect that's what's causing my errors here.
When I click the Google login button, it pulls up the account chooser and then returns nothing. Here's the error in the logs:
GoogleProvider: Error logging in with Google. 10 null
From the Firebase issue tracker, it seems to be associated with a change in your SHA1 fingerprint. Here's the rub: my initial Firebase account has no SHA1 fingerprints associated with it.
Things I've done:
Verified that I have the right SHA token in there, I even brought in the debug ones and I can't seem to get it logged in.
Copied the google-services.json from the correct account.
Tested Twitter, Facebook, and Email and they work flawlessly.
Anyone have any experience here?
Solved it. I was able to find the answer in this Firebase issue tracker thread.
this issue is occuring on debugs builds, right? Every android studio
installation creates a different debug key so you'll have to
regenerate it.
I have two machines that I work on. One is my desktop that I've been pulling keys from (because that's where my release key resides), and another is my laptop where I can code off the cuff. If I want to use the debug build to test this, I need to use the debug SHA1 from the actual machine that I'm running.

Categories

Resources