feat : change app inspector and exception handling

This commit is contained in:
2025-07-12 17:06:29 +03:30
parent e52674de37
commit 0fc16569a6
24 changed files with 472 additions and 322 deletions

View File

@@ -5,7 +5,8 @@ import 'package:rasadyar_auth/hive_registrar.g.dart';
import 'package:rasadyar_core/core.dart';
class TokenStorageService extends GetxService {
static const String _boxName = 'secureBox';
static const String _tokenBoxName = 'TokenBox';
static const String _appBoxName = 'AppBox';
static const String _accessTokenKey = 'accessToken';
static const String _refreshTokenKey = 'refreshToken';
static const String _baseUrlKey = 'baseUrl';
@@ -17,7 +18,7 @@ class TokenStorageService extends GetxService {
RxnString accessToken = RxnString();
RxnString refreshToken = RxnString();
RxnString baseurl= RxnString();
RxnString baseurl = RxnString();
Rxn<Module> appModule = Rxn(null);
Future<void> init() async {
@@ -25,54 +26,61 @@ class TokenStorageService extends GetxService {
Hive.registerAdapters();
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
final encryptionKey = encryptedKey != null ? base64Url.decode(encryptedKey) : Hive.generateSecureKey();
final encryptionKey = encryptedKey != null
? base64Url.decode(encryptedKey)
: Hive.generateSecureKey();
if (encryptedKey == null) {
await _secureStorage.write(key: 'hive_enc_key', value: base64UrlEncode(encryptionKey));
}
await _localStorage.init();
await _localStorage.openBox(_boxName, encryptionCipher: HiveAesCipher(encryptionKey));
await _localStorage.openBox(_tokenBoxName, encryptionCipher: HiveAesCipher(encryptionKey));
await _localStorage.openBox(_appBoxName);
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);
accessToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _accessTokenKey);
refreshToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _refreshTokenKey);
appModule.value = _localStorage.read<Module?>(boxName: _appBoxName, key: _moduleKey);
baseurl.value = _localStorage.read<String?>(boxName: _appBoxName, key: _baseUrlKey);
}
Future<void> saveAccessToken(String token) async {
await _localStorage.save(boxName: _boxName, key: _accessTokenKey, value: token);
await _localStorage.save(boxName: _tokenBoxName, key: _accessTokenKey, value: token);
accessToken.value = token;
accessToken.refresh();
}
Future<void> saveRefreshToken(String token) async {
await _localStorage.save(boxName: _boxName, key: _refreshTokenKey, value: token);
await _localStorage.save(boxName: _tokenBoxName, key: _refreshTokenKey, value: token);
refreshToken.value = token;
refreshToken.refresh();
}
Future<void> saveModule(Module input) async {
await _localStorage.save(boxName: _boxName, key: _moduleKey, value: input);
await _localStorage.save(boxName: _tokenBoxName, key: _moduleKey, value: input);
appModule.value = input;
appModule.refresh();
}
Future<void> deleteTokens() async {
await _localStorage.clear(_boxName);
await _localStorage.clear(_tokenBoxName);
accessToken.value = null;
refreshToken.value = null;
}
Future<void> saveBaseUrl(String url) async {
await _localStorage.save(boxName: _boxName, key: _baseUrlKey, value: url);
await _localStorage.save(boxName: _appBoxName, key: _baseUrlKey, value: url);
baseurl.value = url;
baseurl.refresh();
}
void getBaseUrl() {
var url = _localStorage.read(boxName: _appBoxName, key: _baseUrlKey);
baseurl.value = url;
baseurl.refresh();
}
Future<void> saveApiKey(String key) async {
await _localStorage.save(boxName: _boxName, key: _apiKey, value: key);
await _localStorage.save(boxName: _tokenBoxName, key: _apiKey, value: key);
}
}