question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Calling FirebaseAuthentication.getIdToken() before auth'd causes fatal error & app crashes

See original GitHub issue

Plugin(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:

  1. Install a fresh build of an app.
  2. Don’t authenticate.
  3. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robingenzcommented, Apr 13, 2022

Hello, this was very helpful. I’m a bit confused though. When does the currentUser get set? I’m doing a firebase login with email, then doing the firebase verify email. To check if the email has been verified i call the await FirebaseAuthentication.getIdToken(). I was then running into the same error as @lincolnthree . I’ve resolved it based on your recommendation. However, now when I call the new getIdToken() method, I’m getting a null. How come the user isn’t yet set? Thanks!

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.

1reaction
lincolnthreecommented, Apr 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found