From bde1aab519130c355cba3d92cf3f4be8151f0e89 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Tue, 8 Nov 2022 20:24:29 -0600 Subject: [PATCH] Add AuthService initial cut --- lib/services/auth_service.dart | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/services/auth_service.dart diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart new file mode 100644 index 0000000..5c52641 --- /dev/null +++ b/lib/services/auth_service.dart @@ -0,0 +1,31 @@ +import 'package:flutter/foundation.dart'; +import 'package:result_monad/result_monad.dart'; + +import '../models/exec_error.dart'; +import '../friendica_client.dart'; + +class AuthService extends ChangeNotifier { + FriendicaClient? _friendicaClient; + + Result get currentClient { + if (_friendicaClient == null) { + return Result.error(ExecError( + type: ErrorType.authentication, + message: 'Not logged in', + )); + } + + return Result.ok(_friendicaClient!); + } + + Result updateClient(FriendicaClient newClient) { + _friendicaClient = newClient; + notifyListeners(); + return Result.ok(newClient); + } + + void clearCredentials() { + _friendicaClient = null; + notifyListeners(); + } +}