feat: enhance routing logic and improve login screen validation; add guarded API call for error handling

This commit is contained in:
Nils-Johan Gynther
2026-04-22 07:35:34 +02:00
parent e8de1d3625
commit 2ea18503ef
4 changed files with 117 additions and 54 deletions
@@ -0,0 +1,18 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'api_exception.dart';
import '../../features/auth/data/auth_providers.dart';
/// Executes [call] and automatically logs out the user if the server
/// returns 401 Unauthorized. Re-throws the exception so the calling
/// widget/provider can still display an error if needed.
Future<T> guardedApiCall<T>(Ref ref, Future<T> Function() call) async {
try {
return await call();
} on ApiException catch (e) {
if (e.type == ApiErrorType.unauthorized) {
await ref.read(authStateProvider.notifier).logout();
}
rethrow;
}
}