capacitor-firebase: bug: authStateChange never fires.
Plugin(s): “@capacitor-firebase/authentication”: “^0.5.0”
Platform(s): Android
Current behavior:
When using const result = await FirebaseAuthentication.signInWithGoogle() for example, the login is successful and result.user is returned. However, authStateChange is never fired. Note that this works in web, but NOT on Android.
Expected behavior:
authStateChange needs to be fired on any change in auth state, e.g. re-opening app or signing out.
Steps to reproduce:
Related code:
// capacitor.config.json
"plugins": {
"FirebaseAuthentication": {
"skipNativeAuth": false,
"providers": ["twitter.com", "google.com", "facebook.com"]
},
}
// main.ts
import { FirebaseAuthentication } from "@capacitor-firebase/authentication";
FirebaseAuthentication.removeAllListeners().then(() => {
FirebaseAuthentication.addListener("authStateChange", (result) => {
if (result.user) {
// this never fires
} else {
// this never fires
}
});
});
// Login.vue
const signInWithGoogle = async () => {
try {
const result: SignInResult = await FirebaseAuthentication.signInWithGoogle();
if (result.user) {
return result.user;
}
} catch (err) {
console.log(err);
}
};
Other information: Some potentially relevant logs from Android Studio:
V/Capacitor/FirebaseAuthenticationPlugin: Notifying listeners for event authStateChange D/Capacitor/FirebaseAuthenticationPlugin: No listeners found for event authStateChange V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 81763094, pluginId: FirebaseAuthentication, methodName: addListener V/Capacitor: callback: 81763094, pluginId: FirebaseAuthentication, methodName: addListener, methodData: {“eventName”:“authStateChange”}
Also, it looks like there’s a similar issue that was closed but with no real solution, https://github.com/capawesome-team/capacitor-firebase/issues/56
Capacitor doctor:
Latest Dependencies:
@capacitor/cli: 3.6.0
@capacitor/core: 3.6.0
@capacitor/android: 3.6.0
@capacitor/ios: 3.6.0
Installed Dependencies:
@capacitor/cli: 3.4.3
@capacitor/core: 3.4.3
@capacitor/android: 3.4.3
@capacitor/ios: 3.4.3
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 41 (16 by maintainers)
I will look at it again and possibly consult with the Capacitor team to see what solution they recommend.
@Guiditox Thank you for testing!
@TadasMil If no user is signed in,
getCurrentUsershould return:If this is not the case for you then please create a new issue.
@aaronksaunders That’s right I have all the info I need to solve the problem. Thanks for that! I just wanted to let you know why it’s waiting so long and what the options are. The issue is just waiting for me to find time for it. That’s all! As I said, I do this in my spare time, which is limited. You can send a PR if you want to speed up the process. Or you can sponsor the project. If neither is an option, I can only do it when I find time.
@aaronksaunders I have opened a discussion - Yes frustrating have to work around, this is the core function of the plugin 😕 @robingenz if we figure it out, I’ll come back and update here as it may help to resolve the underlying issue we are working around.