Skip to content

fix(auth, web): restore default persistence to IndexedDB that was incorrectly set to localStorage #9247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/auth/start.md
Original file line number Diff line number Diff line change
@@ -208,7 +208,9 @@ restarts. The user can clear the apps cached data using the device settings,
which will wipe any existing state being stored.

On web platforms, the user's authentication state is stored in
[local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
[IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API).
You can change the persistence to store data in the [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)
using `Persistence.LOCAL`.
If required, you can change this default behavior to only persist
authentication state for the current session, or not at all. To configure these
settings, call the following method `FirebaseAuth.instanceFor(app: Firebase.app(), persistence: Persistence.LOCAL);`.
Original file line number Diff line number Diff line change
@@ -31,10 +31,14 @@ typedef PhoneCodeAutoRetrievalTimeout = void Function(String verificationId);
///
/// Setting a persistence type is only available on web based platforms.
enum Persistence {
/// Indicates that the state will be persisted even when the browser window is
/// Indicates that the state will be persisted in Local Storage even when the browser window is
/// closed.
LOCAL,

/// Indicates that the state will be persisted in IndexedDB even when the browser window is
/// closed.
INDEXED_DB,

/// Indicates that the state will only be stored in memory and will be
/// cleared when the window or activity is refreshed.
NONE,
15 changes: 13 additions & 2 deletions packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@ Auth getAuthInstance(App app, {Persistence? persistence}) {
case Persistence.LOCAL:
setPersistence = auth_interop.browserLocalPersistence;
break;
case Persistence.INDEXED_DB:
setPersistence = auth_interop.indexedDBLocalPersistence;
break;
case Persistence.SESSION:
setPersistence = auth_interop.browserSessionPersistence;
break;
@@ -42,12 +45,17 @@ Auth getAuthInstance(App app, {Persistence? persistence}) {
'popupRedirectResolver': auth_interop.browserPopupRedirectResolver
})));
}
// `browserLocalPersistence` is the default persistence setting.
return Auth.getInstance(auth_interop.initializeAuth(
app.jsObject,
jsify({
'errorMap': auth_interop.debugErrorMap,
'persistence': auth_interop.browserLocalPersistence,
// Default persistence can be seen here
// https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/platform_browser/index.ts#L47
'persistence': [
auth_interop.indexedDBLocalPersistence,
auth_interop.browserLocalPersistence,
auth_interop.browserSessionPersistence
],
'popupRedirectResolver': auth_interop.browserPopupRedirectResolver
})));
}
@@ -543,6 +551,9 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
case Persistence.LOCAL:
instance = auth_interop.browserLocalPersistence;
break;
case Persistence.INDEXED_DB:
instance = auth_interop.indexedDBLocalPersistence;
break;
case Persistence.SESSION:
instance = auth_interop.browserSessionPersistence;
break;
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ external Persistence inMemoryPersistence;
external Persistence browserSessionPersistence;
@JS()
external Persistence browserLocalPersistence;
@JS()
external Persistence indexedDBLocalPersistence;

@JS()
external PromiseJsImpl<ActionCodeInfo> checkActionCode(