Load server configuration
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2025-07-07 21:36:35 +02:00
parent 0a87ac572b
commit 74bb31ecc1
8 changed files with 219 additions and 29 deletions

View File

@ -1,6 +1,7 @@
import 'package:moneymgr_mobile/services/api/api_client.dart';
import 'package:moneymgr_mobile/services/api/api_token.dart';
import 'package:moneymgr_mobile/services/api/auth_api.dart';
import 'package:moneymgr_mobile/services/storage/prefs.dart';
import 'package:moneymgr_mobile/services/storage/secure_storage.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@ -25,7 +26,10 @@ class CurrentAuthState extends _$CurrentAuthState {
/// Will invalidate the state if success and throw an exception in case of failure
Future<void> setAuthToken(ApiToken token) async {
// Attempt to use provided token
await ApiClient(token: token).authInfo();
await ApiClient(
token: token,
prefs: await ref.watch(prefsProvider.future),
).authInfo();
final secureStorage = ref.read(secureStorageProvider).requireValue;
await secureStorage.setToken(token);
@ -37,19 +41,13 @@ class CurrentAuthState extends _$CurrentAuthState {
/// Logs out, deletes the saved token and profile info from storage, and invalidates
/// the state.
void logout() {
// TODO : implement logic
/*final secureStorage = ref.read(secureStorageProvider).requireValue;
// Delete the current [token] and [profile] from secure storage.
secureStorage.remove('token');
Future<void> logout() async {
final secureStorage = ref.read(secureStorageProvider).requireValue;
await secureStorage.removeToken();
ref
// Invalidate the state so the auth state will be updated to unauthenticated.
..invalidateSelf()
// Invalidate the token provider so the API service will no longer use the
// previous token.
..invalidate(tokenProvider);*/
// Invalidate the state so the auth state will be updated to authenticated.
.invalidateSelf();
}
}