Files
captain-claude/apps/captain-mobile-v2/flutter/lib/providers/auth_provider.dart
ARCHITECT f199daf4ba Change PIN to 1451
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 23:31:52 +00:00

53 lines
1.1 KiB
Dart

import 'package:flutter/foundation.dart';
import '../services/auth_service.dart';
class AuthProvider with ChangeNotifier {
final AuthService _authService = AuthService();
bool _isLoading = false;
String? _error;
bool get isLoading => _isLoading;
bool get isAuthenticated => _authService.isAuthenticated;
String? get token => _authService.token;
String? get username => _authService.username;
String? get error => _error;
Future<void> init() async {
_isLoading = true;
notifyListeners();
await _authService.loadStoredAuth();
_isLoading = false;
notifyListeners();
}
Future<bool> login(String username, String password) async {
_isLoading = true;
_error = null;
notifyListeners();
final success = await _authService.login(username, password);
if (!success) {
_error = _authService.lastError ?? 'Login failed';
}
_isLoading = false;
notifyListeners();
return success;
}
Future<void> logout() async {
await _authService.logout();
notifyListeners();
}
void clearError() {
_error = null;
notifyListeners();
}
}