Skip to content

Commit 785c486

Browse files
authored
fix(auth, web): restore default persistence to IndexedDB that was incorrectly set to localStorage (#9247)
1 parent 1a2f226 commit 785c486

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

docs/auth/start.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ restarts. The user can clear the apps cached data using the device settings,
208208
which will wipe any existing state being stored.
209209
210210
On web platforms, the user's authentication state is stored in
211-
[local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
211+
[IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API).
212+
You can change the persistence to store data in the [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)
213+
using `Persistence.LOCAL`.
212214
If required, you can change this default behavior to only persist
213215
authentication state for the current session, or not at all. To configure these
214216
settings, call the following method `FirebaseAuth.instanceFor(app: Firebase.app(), persistence: Persistence.LOCAL);`.

packages/firebase_auth/firebase_auth_platform_interface/lib/src/types.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ typedef PhoneCodeAutoRetrievalTimeout = void Function(String verificationId);
3131
///
3232
/// Setting a persistence type is only available on web based platforms.
3333
enum Persistence {
34-
/// Indicates that the state will be persisted even when the browser window is
34+
/// Indicates that the state will be persisted in Local Storage even when the browser window is
3535
/// closed.
3636
LOCAL,
3737

38+
/// Indicates that the state will be persisted in IndexedDB even when the browser window is
39+
/// closed.
40+
INDEXED_DB,
41+
3842
/// Indicates that the state will only be stored in memory and will be
3943
/// cleared when the window or activity is refreshed.
4044
NONE,

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Auth getAuthInstance(App app, {Persistence? persistence}) {
2727
case Persistence.LOCAL:
2828
setPersistence = auth_interop.browserLocalPersistence;
2929
break;
30+
case Persistence.INDEXED_DB:
31+
setPersistence = auth_interop.indexedDBLocalPersistence;
32+
break;
3033
case Persistence.SESSION:
3134
setPersistence = auth_interop.browserSessionPersistence;
3235
break;
@@ -42,12 +45,17 @@ Auth getAuthInstance(App app, {Persistence? persistence}) {
4245
'popupRedirectResolver': auth_interop.browserPopupRedirectResolver
4346
})));
4447
}
45-
// `browserLocalPersistence` is the default persistence setting.
4648
return Auth.getInstance(auth_interop.initializeAuth(
4749
app.jsObject,
4850
jsify({
4951
'errorMap': auth_interop.debugErrorMap,
50-
'persistence': auth_interop.browserLocalPersistence,
52+
// Default persistence can be seen here
53+
// https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/platform_browser/index.ts#L47
54+
'persistence': [
55+
auth_interop.indexedDBLocalPersistence,
56+
auth_interop.browserLocalPersistence,
57+
auth_interop.browserSessionPersistence
58+
],
5159
'popupRedirectResolver': auth_interop.browserPopupRedirectResolver
5260
})));
5361
}
@@ -543,6 +551,9 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
543551
case Persistence.LOCAL:
544552
instance = auth_interop.browserLocalPersistence;
545553
break;
554+
case Persistence.INDEXED_DB:
555+
instance = auth_interop.indexedDBLocalPersistence;
556+
break;
546557
case Persistence.SESSION:
547558
instance = auth_interop.browserSessionPersistence;
548559
break;

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth_interop.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ external Persistence inMemoryPersistence;
3131
external Persistence browserSessionPersistence;
3232
@JS()
3333
external Persistence browserLocalPersistence;
34+
@JS()
35+
external Persistence indexedDBLocalPersistence;
3436

3537
@JS()
3638
external PromiseJsImpl<ActionCodeInfo> checkActionCode(

0 commit comments

Comments
 (0)