43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../../auth/token_storage.dart';
|
|
import '../../marianumconnect_api.dart';
|
|
import '../../marianumconnect_endpoint.dart';
|
|
import '../../marianumconnect_query.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 extends MarianumConnectQuery {
|
|
final MarianumConnectTokenStorage _tokenStorage;
|
|
|
|
AuthLogout({
|
|
MarianumConnectTokenStorage tokenStorage =
|
|
const MarianumConnectTokenStorage(),
|
|
super.dio,
|
|
}) : _tokenStorage = tokenStorage;
|
|
|
|
Future<void> run() async {
|
|
try {
|
|
await dio.post<void>(endpoint('auth/logout'));
|
|
} on DioException catch (_) {
|
|
// ignore — local clear below still happens
|
|
} finally {
|
|
await _tokenStorage.clear();
|
|
}
|
|
}
|
|
|
|
/// Revokes the token of an inactive account; the stored (active) token is
|
|
/// left alone. Best-effort.
|
|
static Future<void> revoke(String token) async {
|
|
try {
|
|
await MarianumConnectApi.plainDio().post<void>(
|
|
MarianumConnectEndpoint.resolve('auth/logout'),
|
|
options: Options(headers: {'Authorization': 'Bearer $token'}),
|
|
);
|
|
} on DioException catch (_) {
|
|
// ignore
|
|
}
|
|
}
|
|
}
|