Whenever my user logs in, my app creates this key that gets returned in my call to AsyncStorage.getAllKeys();
"firebase:authUser:[redacted]:[DEFAULT]",
I do not make any calls to AsyncStorage.set on login so I am very confused as to what this is and how it is getting there.
Related
I'm facing the same problem as this guy question
But his accepted answer didn't helped me.
The problem:
When an user signs out, and another different user signs in, all data shown on my app is from the previous signed out user due to firebase caching system. I searched about this issue and found a solution that consists in calling this method:
FirebaseFirestore.instance.clearPersistence();
But everytime and everywhere I place this line of code, throws an exception saying I cannot call this method when the client is running:
Exception has occurred.
PlatformException (PlatformException(failed-precondition, Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., {code: failed-precondition, message: Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., nativeErrorMessage: Persistence cannot be cleared while the client is running., nativeErrorCode: 9}))
so, how to call this method? or better, is there a best way to solve this problem?
It seems it's necessary to terminate the FirebaseFirestore.instance first.
At the end of my log off method I call:
await FirebaseFirestore.instance.terminate();
await FirebaseFirestore.instance.clearPersistence();
I get no errors thrown and everything seems to be working as it should now.
You should call it immediately after you initialize Firebase, and before you make the first query.
add this to your Login Button 'onPressed':
FirebaseFirestore.instance.terminate();
FirebaseFirestore.instance
.clearPersistence()
.then((value) => signinUser(email, password, context));
Please help, I want to test a service method - and during this testing I want to forcefully log-in a user by providing the user name and password - this will not be used for production, simply for a test I am conducting. But when I get the sign in manager and call the PasswordSignInAsync I receive a strange error, this error is not generated when going via Login.cshtml.cs code which reads the same?
This is my Firebase database structure:
// Registered users
users{
9BKlHH11NvU1kQdpwSaFshNJn8C2{
foo: foo
bar: bar
B5Lq9RquOvcK7CLhh1Mdq0qWCqO2{
foo: foo
bar: bar
// Connected users inside the lobby
Lobby{
9BKlHH11NvU1kQdpwSaFshNJn8C2,
B5Lq9RquOvcK7CLhh1Mdq0qWCqO2
So everytime a registered user logs in and enters the lobby, his uid is added to the lobby list so everybody sees him. If he logs out there's a process to remove him from the lobby list.
Now the problem is; what would be the best approach to remove a user that has closed the browser/app without leaving the lobby so the rest of the users don't see someone that is not actually connected in that list? Is there a timeout function maybe?
There is no timeout function.
Though on the application end, you can add and check the entry in Lobby, and send the beacon request in every 10 or 30 sec or more to make the entry in lobby valid.
And in the UI, while listing Users in the Lobby, if Lobby entry is older than the beacon time, you can either not list them or send a request to remove them.
It will be better to just skip the addition of that User in the UI, let the old entries be there. Sending the removal request will be contradicting, and will arise conflicts if more front ends are sending request to remove same User from Lobby. But, its all up to your app structure and Use Case.
When a user registers on my system, I create the user internally, and then allow the user to register with Firebase using the firebase client lib. This generates a session token for the user. Later, when a user starts the app again, the app automatically logs the user in like this:
ref.authWithCustomToken(sessionToken, function(error, authData) {...
debugger
I have verified that the sessionToken is available when the function is executed, but debugger is never reached, and no error is ever emitted.
Any help is appreciated!
I know it's a bit late, but I experienced a similar problem and it had me scratching my head for a while, so just in case it helps somebody else, here's what I found.
If I run authWithCustomToken with a token generated with one uid (uid1) and then run it again on the same ref with a different uid (uid2), the callback doesn't get fired the second time around.
In my case, I had declared the same ref in different modules that were used in the same node process and was trying to authenticate them with different uids. Although I had declared the ref twice, Firebase still saw it as the same ref because it was in the same process and referred to the same Firebase location. By declaring and authorising the ref in a parent module, I was then able to use onAuth in the child modules and the onAuth callbacks all fired as expected.
I had a similar problem with iOS, authWithCustomToken callback was never called right after install.
All consecutive launches worked fine.
My findings might be related so I thought I share them.
Problem was I called
func applicationWillResignActive(application: UIApplication) {
Firebase.goOffline()
}
func applicationWillEnterForeground(application: UIApplication) {
Firebase.goOnline()
}
in AppDelegate. Turns out if you call Firebase.goOnline() without logging in first it messes up the callback. Once I removed those two lines everything worked fine.
Or will it cause an error?
Example:
authClient = new FirebaseAuthClient(baseRef, function(error, user) { ... });
// Try to log in...
authClient.login('password', {email: 'some_email', password: 'some_password'});
// Before the callback from the previous line of code executes...
// Oh wait, I forgot to signup in the first place, let me do that:
authClient.createUser('some_email', 'some_password', function(error, user) { ... });
While it is safe to call those methods before the previous one has completed, in that you won't break corrupt data nor will exceptions be thrown, you might see some unexpected (and non-deterministic) behavior, depending upon the state of the user's account and session.
For example, if an existing session is detected (via looking at the browser cookie and localStorage), the FirebaseAuthClient will attempt to resume it which involves a quick verification step. Calling login before that step has completed will have different effects depending upon the user's account status.
Continuing that example, if the account exists and credentials are correct, you'll override the existing session and your callback will be invoked twice (once for the existing session, and once for the new one). If the account does not exist, or the credentials are incorrect, you may first receive one callback for the correct session, and then an error after receiving the bad credentials.
It might be helpful to hear a bit more about your specific use case and desired user experience so we may determine the clearest way to structure your code. Hope that helps!