| // Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'dart:js_interop'; |
| import 'package:firebase_app_check/firebase_app_check.dart'; |
| import 'package:firebase_core/firebase_core.dart'; |
| import 'package:jaspr/client.dart'; |
| import 'package:web/web.dart' as web; |
| |
| import 'features/preview/views/share_route.dart'; |
| import 'firebase_options.dart'; |
| import 'share.client.options.dart'; |
| |
| const _useFirebaseAppCheckDebug = bool.fromEnvironment( |
| 'USE_FIREBASE_APPCHECK_DEBUG', |
| ); |
| const _firebaseAppCheckSiteKey = String.fromEnvironment( |
| 'FIREBASE_APPCHECK_SITE_KEY', |
| ); |
| const _firebaseAppCheckDebugToken = String.fromEnvironment( |
| 'FIREBASE_APPCHECK_DEBUG_TOKEN', |
| ); |
| |
| Future<void> main() async { |
| Jaspr.initializeApp(options: defaultClientOptions); |
| |
| try { |
| web.window.navigator.serviceWorker.register('sw.js'.toJS); |
| } catch (_) {} |
| |
| await Firebase.initializeApp( |
| options: DefaultFirebaseOptions.currentPlatform, |
| ); |
| |
| if (_useFirebaseAppCheckDebug) { |
| await FirebaseAppCheck.instance.activate( |
| providerWeb: WebDebugProvider( |
| debugToken: _firebaseAppCheckDebugToken.isEmpty ? null : _firebaseAppCheckDebugToken, |
| ), |
| ); |
| } else { |
| if (_firebaseAppCheckSiteKey.isEmpty) { |
| throw StateError( |
| 'Missing FIREBASE_APPCHECK_SITE_KEY in .env.local or --dart-define to initialize the reCAPTCHA v3 provider.', |
| ); |
| } |
| await FirebaseAppCheck.instance.activate( |
| providerWeb: ReCaptchaV3Provider( |
| _firebaseAppCheckSiteKey, |
| ), |
| ); |
| } |
| await FirebaseAppCheck.instance.setTokenAutoRefreshEnabled(true); |
| |
| final uri = Uri.parse(web.window.location.href); |
| final hash = uri.queryParameters['id'] ?? ''; |
| |
| runApp(ShareRoute(hash: hash)); |
| } |