flutter_dashboard/lib/services/auth_service.dart
jdysya 66f46980f0 feat: 更新应用配置和依赖
- 修改应用 ID 为 top.jdysya.dashboard
- 添加互联网权限
- 更新签名配置
- 修改测试目标应用 ID
- 更新依赖版本:
  - async: 2.12.0 -> 2.13.0
  - fake_async: 1.3.2 -> 1.3.3
  - leak_tracker: 10.0.8 -> 10.0.9
  - vm_service: 14.3.1 -> 15.0.0
- 移除了一些冗余的代码和配置
2025-06-09 23:42:09 +08:00

60 lines
1.9 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;
final Map<String, String> _credentials = {};
bool get isAuthenticated => _isAuthenticated;
Map<String, String> get credentials => _credentials;
Future<void> saveConfigs(String key, String value) async {
await _storage.write(key: key, value: value);
_credentials[key] = value;
_isAuthenticated = true;
notifyListeners();
}
Future<void> loadConfigs() async {
final leetcodeCookie = await _storage.read(key: 'leetcode_cookie');
final leetcodeUserSlug = await _storage.read(key: 'leetcode_user_slug');
final giteaToken = await _storage.read(key: 'gitea_token');
final giteaUserName = await _storage.read(key: 'gitea_username');
final kodboxToken = await _storage.read(key: 'kodbox_token');
final githubUserName = await _storage.read(key: 'github_username');
final githubToken = await _storage.read(key: 'github_token');
if (leetcodeCookie != null) {
_credentials['leetcode_cookie'] = leetcodeCookie;
}
if (leetcodeUserSlug != null) {
_credentials['leetcode_user_slug'] = leetcodeUserSlug;
}
if (giteaToken != null) {
_credentials['gitea_token'] = giteaToken;
}
if (giteaUserName != null) {
_credentials['gitea_username'] = giteaUserName;
}
if (kodboxToken != null) {
_credentials['kodbox_token'] = kodboxToken;
}
if (githubUserName != null) {
_credentials['github_username'] = githubUserName;
}
if (githubToken != null) {
_credentials['github_token'] = githubToken;
}
_isAuthenticated = true;
notifyListeners();
}
Future<void> logout() async {
await _storage.deleteAll();
_credentials.clear();
_isAuthenticated = false;
notifyListeners();
}
}