feat : auth for new module

This commit is contained in:
MrM
2025-06-03 22:52:21 +03:30
parent ae18a5f648
commit 2b4c019c55
16 changed files with 314 additions and 133 deletions

View File

@@ -8,6 +8,8 @@ class TokenStorageService extends GetxService {
static const String _boxName = 'secureBox';
static const String _accessTokenKey = 'accessToken';
static const String _refreshTokenKey = 'refreshToken';
static const String _baseUrlKey = 'baseUrl';
static const String _apiKey = 'apiKey';
static const String _moduleKey = 'moduleSelected';
final FlutterSecureStorage _secureStorage = FlutterSecureStorage();
@@ -15,6 +17,7 @@ class TokenStorageService extends GetxService {
RxnString accessToken = RxnString();
RxnString refreshToken = RxnString();
RxnString baseurl= RxnString();
Rxn<Module> appModule = Rxn(null);
Future<void> init() async {
@@ -34,6 +37,7 @@ class TokenStorageService extends GetxService {
accessToken.value = _localStorage.read<String?>(boxName: _boxName, key: _accessTokenKey);
refreshToken.value = _localStorage.read<String?>(boxName: _boxName, key: _refreshTokenKey);
appModule.value = _localStorage.read<Module?>(boxName: _boxName, key: _moduleKey);
baseurl.value = _localStorage.read<String?>(boxName: _boxName, key: _baseUrlKey);
}
Future<void> saveAccessToken(String token) async {
@@ -59,4 +63,16 @@ class TokenStorageService extends GetxService {
accessToken.value = null;
refreshToken.value = null;
}
Future<void> saveBaseUrl(String url) async {
await _localStorage.save(boxName: _boxName, key: _baseUrlKey, value: url);
baseurl.value = url;
baseurl.refresh();
}
Future<void> saveApiKey(String key) async {
await _localStorage.save(boxName: _boxName, key: _apiKey, value: key);
}
}