31 lines
908 B
Dart
31 lines
908 B
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../../auth/token_storage.dart';
|
|
import '../../marianumconnect_api.dart';
|
|
import '../../marianumconnect_endpoint.dart';
|
|
|
|
/// Revokes the stored MC bearer token both server-side and locally. Best-effort
|
|
/// — a network error still clears the local token so the user isn't stuck with
|
|
/// an unusable session.
|
|
class AuthLogout {
|
|
final MarianumConnectTokenStorage _tokenStorage;
|
|
final Dio _dio;
|
|
|
|
AuthLogout({
|
|
MarianumConnectTokenStorage tokenStorage =
|
|
const MarianumConnectTokenStorage(),
|
|
Dio? dio,
|
|
}) : _tokenStorage = tokenStorage,
|
|
_dio = dio ?? MarianumConnectApi.dio();
|
|
|
|
Future<void> run() async {
|
|
try {
|
|
await _dio.post<void>(MarianumConnectEndpoint.resolve('auth/logout'));
|
|
} on DioException catch (_) {
|
|
// ignore — local clear below still happens
|
|
} finally {
|
|
await _tokenStorage.clear();
|
|
}
|
|
}
|
|
}
|