Skip to content

Commit

Permalink
fix(auth, web): flutter 3.19.0 interop broke auth persistence setti…
Browse files Browse the repository at this point in the history
…ng. Updated the way we initialise JS Map inline with latest interop. (#12338)
  • Loading branch information
russellwheatley committed Feb 16, 2024
1 parent fdde75b commit 9d5480f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/all_plugins.yaml
Expand Up @@ -86,6 +86,7 @@ jobs:
- uses: Homebrew/actions/setup-homebrew@master
- name: 'Install Tools'
run: |
brew install python3
flutter pub global activate flutter_plugin_tools
brew install swiftformat
brew install clang-format
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e_tests.yaml
Expand Up @@ -272,7 +272,7 @@ jobs:
key: firebase-emulators-v3-${{ github.run_id }}
restore-keys: firebase-emulators-v3
- name: Start Firebase Emulator
run: cd ./.github/workflows/scripts && ./start-firebase-emulator.sh
run: sudo chown -R 501:20 "/Users/runner/.npm" && cd ./.github/workflows/scripts && ./start-firebase-emulator.sh
- name: 'E2E Tests'
working-directory: ${{ matrix.working_directory }}
# Web devices are not supported for the `flutter test` command yet. As a
Expand Down
30 changes: 18 additions & 12 deletions packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart
Expand Up @@ -21,19 +21,23 @@ export 'auth_interop.dart';

/// Given an AppJSImp, return the Auth instance.
Auth getAuthInstance(App app) {
return Auth.getInstance(auth_interop.initializeAuth(
// Default persistence can be seen here
// https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/platform_browser/index.ts#L47
final persistences = [
auth_interop.indexedDBLocalPersistence,
auth_interop.browserLocalPersistence,
auth_interop.browserSessionPersistence,
];
return Auth.getInstance(
auth_interop.initializeAuth(
app.jsObject,
jsify({
'errorMap': auth_interop.debugErrorMap,
// 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
})));
auth_interop.AuthOptions(
errorMap: auth_interop.debugErrorMap,
persistence: persistences.toJS,
popupRedirectResolver: auth_interop.browserPopupRedirectResolver,
),
),
);
}

/// User profile information, visible only to the Firebase project's apps.
Expand Down Expand Up @@ -379,6 +383,7 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
}

JSFunction? _onAuthUnsubscribe;

// TODO(rrousselGit): fix memory leak – the controller isn't closed even in onCancel
// ignore: close_sinks
StreamController<User?>? _changeController;
Expand Down Expand Up @@ -420,6 +425,7 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
}

JSFunction? _onIdTokenChangedUnsubscribe;

// TODO(rrousselGit): fix memory leak – the controller isn't closed even in onCancel
// ignore: close_sinks
StreamController<User?>? _idTokenChangedController;
Expand Down
Expand Up @@ -18,10 +18,21 @@ import 'package:firebase_core_web/firebase_core_web_interop.dart';
external AuthJsImpl getAuth([AppJsImpl? app]);

@JS()
external AuthJsImpl initializeAuth(AppJsImpl app, JSAny debugErrorMap);
external AuthJsImpl initializeAuth(AppJsImpl app, AuthOptions authOptions);

extension type AuthOptions._(JSObject o) implements JSObject {
external AuthOptions({
JSObject errorMap,
JSArray? persistence,
JSObject? popupRedirectResolver,
});
external JSObject? get errorMap;
external JSArray? get persistence;
external JSObject? get popupRedirectResolver;
}

@JS('debugErrorMap')
external JSAny get debugErrorMap;
external JSObject get debugErrorMap;

@JS()
external JSPromise applyActionCode(AuthJsImpl auth, JSString oobCode);
Expand Down Expand Up @@ -348,10 +359,7 @@ extension UserJsImplExtension on UserJsImpl {
///
/// See: <https://firebase.google.com/docs/reference/js/firebase.auth.Auth#.Persistence>
@JS('Persistence')
@staticInterop
class Persistence {}

extension PersistenceExtension on Persistence {
extension type Persistence._(JSObject _) implements JSObject {
external JSString get type;
}

Expand Down Expand Up @@ -809,7 +817,7 @@ extension AdditionalUserInfoJsImplExtension on AdditionalUserInfoJsImpl {
@staticInterop
@anonymous
class AuthSettings {
// external factory AuthSettings({JSBoolean appVerificationDisabledForTesting});
// external factory AuthSettings({JSBoolean appVerificationDisabledForTesting});
}

extension AuthSettingsExtension on AuthSettings {
Expand All @@ -819,7 +827,7 @@ extension AuthSettingsExtension on AuthSettings {

@JS()
@staticInterop
external JSAny get browserPopupRedirectResolver;
external JSObject get browserPopupRedirectResolver;

/// https://firebase.google.com/docs/reference/js/auth.multifactoruser.md#multifactoruser_interface
@JS()
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/firebase_auth_web/pubspec.yaml
Expand Up @@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/firebas
version: 5.9.4

environment:
sdk: '>=3.2.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

This comment has been minimized.

Copy link
@deepak-agendaboa

deepak-agendaboa Feb 19, 2024

@russellwheatley Why this constraint is minimum 3.3?
In the firebase_core_web, it is 3.2.

Having this as 3.3 is forcing us to use Flutter 3.19

flutter: '>=3.3.0'

dependencies:
Expand Down

0 comments on commit 9d5480f

Please sign in to comment.