AppFlowy/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
Nathan.fooo ec80f72c8f
feat: af cloud database (#3684)
* chore: forece user to logout when token is invalid

* chore: update client api rev
2023-10-12 20:25:00 +08:00

30 lines
837 B
Dart

import 'package:appflowy/env/env.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy/user/application/user_auth_listener.dart';
class InitAppFlowyCloudTask extends LaunchTask {
final _authStateListener = UserAuthStateListener();
bool isLoggingOut = false;
@override
Future<void> initialize(LaunchContext context) async {
if (!isAppFlowyCloudEnabled) {
return;
}
_authStateListener.start(
didSignIn: () {
isLoggingOut = false;
},
onInvalidAuth: (message) async {
await getIt<AuthService>().signOut();
// TODO(nathan): Show a dialog to notify the user that the session is expired.
if (!isLoggingOut) {
await runAppFlowy();
}
},
);
}
}