firebase auth suddenly saving to indexedDB on Chrome

5,076 views
Skip to first unread message

Rich DAlfonso

unread,
Mar 23, 2018, 3:44:58 PM3/23/18
to Firebase Google Group
I'm having a real weird issue.

My firebase login (firebase:authUser:GUID:[DEFAULT]) was saving to localStorage and I was accessing localStorage in my code without any issues.

Suddenly, on production, it's saving the login to indexedDB. I'm using Chrome browser.

This is an angular 4 / TypeScript / application.
It was working without using any firebase.auth().setPersistence. 

I've tried explicitly setting but even that fails on production.

  firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
      .then(() => {
....

Anyone else have this puzzling issue?

Bassam

unread,
Mar 25, 2018, 7:23:40 PM3/25/18
to Firebase Google Group
Hey Rich,
Firebase Auth migrated from localStorage to indexedDB (for LOCAL persistence) starting from version 4.12.0.
The reason for doing so are many. Among them:
1. Supporting indexedDB will make Firebase Auth usable in service workers and web workers.
2. indexedDB is better supported and more reliable in many environments such as Cordova/Ionic, chrome apps, etc.

Best regards,
Bassam

Rich DAlfonso

unread,
Mar 26, 2018, 7:32:51 PM3/26/18
to Firebase Google Group
Bassam,

When was version 4.12.0 deployed?

Can you point me to documentation on how to access indexedDB?

Bassam

unread,
Mar 26, 2018, 8:40:30 PM3/26/18
to Firebase Google Group
This was deployed in https://firebase.google.com/support/release-notes/js#4.12.0

indexedDB is a native JS API. Accessing it is well documented online.
I recommend that you stop relying on internal implementations of how we persist Auth state as that is subject to change and instead use our public APIs. Basically, anything that is not part of our public API is subject to change.
If you think there is some missing functionality that needs to be provided (not currently covered by our API), feel free to file a feature request for it.

Best regards,
Bassam

Thomas

unread,
Mar 29, 2018, 1:21:21 PM3/29/18
to Firebase Google Group
We used the localStorage login information to support cross-origin login syncing. Specifically, to allow a user to a login once at our website and then pass that information to an accompanying Chrome extension so they were also logged in on the Chrome extension.

Is there an alternative way to do implement this syncing using the existing Firebase API functions?

Bassam

unread,
Mar 29, 2018, 1:28:37 PM3/29/18
to Firebase Google Group
How did you use localStorage to support cross-origin syncing? localStorage is single host origin only just like indexedDB.

Bassam

Thomas

unread,
Mar 29, 2018, 11:38:52 PM3/29/18
to Firebase Google Group
We have two origins: Origin A and Origin B.  If the user logins at Origin A we want the also to be logged at Origin B without them needing to login again.

The method is roughly:

1) On Origin A a listener is set up for auth.onAuthStateChange
2) When the user signs in on Origin A, the listener from Step (1) detects this and extracts the localStorage contents of firebase:authUser:GUID:[DEFAULT]
3) This contents is then handed off to Origin B via a mechanism like postMessage
4) Origin B then writes it to its own localStorage at the key firebase:authUser:GUID:[DEFAULT]
5) The next time the user loads Origin B, Firebase reads the information and they are logged in.

This is a bit clunky but works quite well. If Firebase exposed some form of auth.getFullCredentials() and auth.setFullCredentials() that would return and then read the authentication information that was stored in localStorage, that would be an even better solution.

Bassam

unread,
Mar 30, 2018, 3:28:55 AM3/30/18
to Firebase Google Group
Hey Thomas, everything you described can be done with indexedDB. The onAuthStateChanged listener should still trigger across tabs on Auth state changes.

Best regards,
Bassam
Reply all
Reply to author
Forward
0 new messages