34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../api/marianumconnect/queries/auth_logout/auth_logout.dart';
|
|
import '../auth_link/guardian_link_listener.dart';
|
|
import '../push/push_registration.dart';
|
|
import 'session_manager.dart';
|
|
|
|
abstract final class SessionLifecycle {
|
|
/// Why the last sign-out happened, when the user did not ask for it. The
|
|
/// login screen shows it once and clears it — without it an expired session
|
|
/// just drops the user on the login screen with no explanation.
|
|
static final ValueNotifier<String?> signOutNotice = ValueNotifier(null);
|
|
|
|
/// Ordered teardown: unregister push and revoke the Nextcloud app passwords
|
|
/// (while those credentials still exist), then revoke the MC bearer token,
|
|
/// finally wipe the local session. Each step is best-effort so an offline
|
|
/// sign-out still reaches a clean local state.
|
|
static Future<void> signOut({String? notice}) async {
|
|
signOutNotice.value = notice;
|
|
try {
|
|
await PushRegistration().logoutCleanup();
|
|
} on Object catch (e) {
|
|
log('Sign-out: push cleanup failed: $e');
|
|
}
|
|
await AuthLogout().run();
|
|
await SessionManager().signOut();
|
|
// A login link that arrived while signed in must not be replayed on the
|
|
// login screen that follows.
|
|
GuardianLinkListener.clear();
|
|
}
|
|
}
|