Search code examples
androidfirebasewebviewfirebase-authenticationfirebase-hosting

User authentication is not persisted on WebView


I'm creating an Android app that has a WebView which accesses my website hosted using Firebase Hosting.

If I sign into the website using email/password credentials and then refresh or navigate to another page, Firebase loses my login information.

I tried to force Firebase to keep my credentials using firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL) but it throws this error in the WebView console:

Uncaught Error: The current environment does not support the specified persistence type.

As a side note, I tried logging in on other services, such as YouTube and Google to see if it was a browser cache problem, but the session was persisted normally, even after I refreshed the page, navigated or reopened the Android app.

I also tested the Android app using the emulator (running Android 8.0) and a phone (Android 6.0).

Does somebody know what's going on here?


Solution

  • You need to enable DOM storage in your webview as Firebase Auth depends on web storage (localStorage/indexedDB) to store the Auth state.

    webview.getSettings().setDomStorageEnabled(true);