appflowy_cloud_task.dart 837 B

1234567891011121314151617181920212223242526272829
  1. import 'package:appflowy/env/env.dart';
  2. import 'package:appflowy/startup/startup.dart';
  3. import 'package:appflowy/user/application/auth/auth_service.dart';
  4. import 'package:appflowy/user/application/user_auth_listener.dart';
  5. class InitAppFlowyCloudTask extends LaunchTask {
  6. final _authStateListener = UserAuthStateListener();
  7. bool isLoggingOut = false;
  8. @override
  9. Future<void> initialize(LaunchContext context) async {
  10. if (!isAppFlowyCloudEnabled) {
  11. return;
  12. }
  13. _authStateListener.start(
  14. didSignIn: () {
  15. isLoggingOut = false;
  16. },
  17. onInvalidAuth: (message) async {
  18. await getIt<AuthService>().signOut();
  19. // TODO(nathan): Show a dialog to notify the user that the session is expired.
  20. if (!isLoggingOut) {
  21. await runAppFlowy();
  22. }
  23. },
  24. );
  25. }
  26. }