35 lines
1.0 KiB
Dart
35 lines
1.0 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
class AuthService extends ChangeNotifier {
|
|
final _storage = const FlutterSecureStorage();
|
|
bool _isAuthenticated = false;
|
|
Map<String, String> _credentials = {};
|
|
|
|
bool get isAuthenticated => _isAuthenticated;
|
|
Map<String, String> get credentials => _credentials;
|
|
|
|
Future<void> saveCredentials(String platform, String cookie) async {
|
|
await _storage.write(key: 'cookie_$platform', value: cookie);
|
|
_credentials[platform] = cookie;
|
|
_isAuthenticated = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> loadCredentials() async {
|
|
final leetcodeCookie = await _storage.read(key: 'cookie_leetcode');
|
|
if (leetcodeCookie != null) {
|
|
_credentials['leetcode'] = leetcodeCookie;
|
|
_isAuthenticated = true;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
await _storage.deleteAll();
|
|
_credentials.clear();
|
|
_isAuthenticated = false;
|
|
notifyListeners();
|
|
}
|
|
}
|