bug: Calling FirebaseAuthentication.getIdToken() before auth'd causes fatal error & app crashes
See original GitHub issuePlugin(s):
authentication 0.21
Platform(s):
Android
Current behavior:
call FirebaseAuthentication.getIdToken()
from the JS client before an ID token exists in the Native cache.
E/Capacitor: Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:592)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.auth.FirebaseUser.getIdToken(boolean)' on a null object reference
at dev.robingenz.capacitorjs.plugins.firebase.authentication.FirebaseAuthentication.getIdToken(FirebaseAuthentication.java:79)
at dev.robingenz.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationPlugin.getIdToken(FirebaseAuthenticationPlugin.java:43)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:592)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
E/AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
Process: com.maritlabs.topdecked.mtg, PID: 17988
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:601)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:592)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.auth.FirebaseUser.getIdToken(boolean)' on a null object reference
at dev.robingenz.capacitorjs.plugins.firebase.authentication.FirebaseAuthentication.getIdToken(FirebaseAuthentication.java:79)
at dev.robingenz.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationPlugin.getIdToken(FirebaseAuthenticationPlugin.java:43)
Expected behavior:
Don’t crash 😃 Just return null.
Steps to reproduce:
- Install a fresh build of an app.
- Don’t authenticate.
- Call
FirebaseAuthentication.getIdToken()
Related code:
insert short code snippets here
Other information:
Capacitor doctor:
mshark:topdecked-unified lincoln$ npx cap doctor
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 3.4.3
@capacitor/core: 3.4.3
@capacitor/android: 3.4.3
@capacitor/ios: 3.4.3
Installed Dependencies:
@capacitor/cli: 3.4.3
@capacitor/ios: 3.4.3
@capacitor/android: 3.4.3
@capacitor/core: 3.4.3
[success] iOS looking great! 👌
[success] Android looking great! 👌
mshark:topdecked-unified lincoln$
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
[firebase_auth] App crashing when calling ... - GitHub
Bug report Describe the bug After updating my flutter application to use firebase_auth 0.20.0, the app is crashing on my Android emulator ...
Read more >app crash while using firebase phone Auth in android
When I call the 'verifyPhoneNumber' method of firebase to send OTP, my app getting crashes and exits leaving no error message. Here's my...
Read more >crash iOS 14 - Unbalanced call to dispatch_group_leave()
I have received this report through firebase analytics(Crashlytics) and I have no idea what it is. Would you help me? The problem is...
Read more >Detect and diagnose crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >Bug - Android 12 App crashes on startup due to error with ...
gradle file in Unity (In Unity, set the following checkbox to true to create a custom main gradle template file called mainTemplate.gradle: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
currentUser
is set as soon as a user logs in via one of the signIn methods of the plugin. Since the plugin does not yet support password authentication (see #27), I assume you are using the Firebase JS SDK directly. If that is the case, then you are only logging the user in on the web layer and not on the native layer. This results in the currentUser not being set on native devices, as the plugin does not know it.Excellent. Thanks for confirming. That’s the workaround I ended up with as well 😃 PS. Thanks for this fantastic library. A bit more complex to set up than previous alternatives, but VERY nicely done.