ocarina2/lib/api/login_manager.dart

30 lines
1.1 KiB
Dart
Raw Permalink Normal View History

2024-05-23 19:14:08 +02:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
const _storage = FlutterSecureStorage();
/// Manages login details
class LoginManager {
/// Checks if user has saved login details
static Future<bool> get hasSavedLogin async {
return (await _storage.containsKey(key: "sub_user")) &&
(await _storage.containsKey(key: "sub_pass")) &&
(await _storage.containsKey(key: "sub_url"));
}
/// Stores log in details into secure storage
static Future<void> saveDetails(String user, String pass, String url) async {
await _storage.write(key: "sub_user", value: user);
await _storage.write(key: "sub_pass", value: pass);
await _storage.write(key: "sub_url", value: url);
}
/// Returns log in details from secure storage
static Future<Map<String, String>?> getDetails() async {
final user = await _storage.read(key: "sub_user");
final pass = await _storage.read(key: "sub_pass");
final url = await _storage.read(key: "sub_url");
if (user == null || pass == null || url == null) return null;
return {"user": user, "pass": pass, "url": url};
}
}