Skip to content

Commit

Permalink
fix(app-check, web): ensure exact same streams are not unsubscribed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 9, 2024
1 parent 20d0002 commit 93f1517
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:js_interop_unsafe';

import 'package:firebase_app_check_platform_interface/firebase_app_check_platform_interface.dart';
import 'package:firebase_core_web/firebase_core_web_interop.dart';
import 'package:flutter/foundation.dart';

import 'app_check_interop.dart' as app_check_interop;

Expand Down Expand Up @@ -76,8 +77,21 @@ class AppCheck extends JsObjectWrapper<app_check_interop.AppCheckJsImpl> {
// ignore: close_sinks
_idTokenChangedController;

String _appCheckWindowsKey(String appName) =>
'flutterfire-${appName}_onTokenChanged';
// purely for debug mode and tracking listeners to clean up on "hot restart"
final Map<String, int> _tokenListeners = {};
String _appCheckWindowsKey(String appName) {
if (kDebugMode) {
final key = 'flutterfire-${appName}_onTokenChanged';
if (_tokenListeners.containsKey(key)) {
_tokenListeners[key] = _tokenListeners[key]! + 1;
} else {
_tokenListeners[key] = 0;
}
return '$key-${_tokenListeners[key]}';
}
return 'no-op';
}

Stream<app_check_interop.AppCheckTokenResult> onTokenChanged(String appName) {
final appCheckWindowsKey = _appCheckWindowsKey(appName);
unsubscribeWindowsListener(appCheckWindowsKey);
Expand Down

0 comments on commit 93f1517

Please sign in to comment.