feat : new method in token_storage_service.dart

use core local_repository
This commit is contained in:
2025-05-14 10:02:03 +03:30
parent 2615f35416
commit 9a8ab8467b

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/injection/di.dart';
@@ -23,36 +24,32 @@ class TokenStorageService extends GetxService {
);
}
await Hive.initFlutter();
await Hive.openBox(
await _localStorage.init();
await _localStorage.openBox(
_boxName,
encryptionCipher: HiveAesCipher(encryptionKey),
);
}
Future<void> saveAccessToken(String token) async {
final box = Hive.box(_boxName);
await box.put(_accessTokenKey, token);
}
Future<void> saveAccessToken(String token) async => await _localStorage.save(
boxName: _boxName,
key: _accessTokenKey,
value: token,
);
Future<void> saveRefreshToken(String token) async {
final box = Hive.box(_boxName);
await box.put(_refreshTokenKey, token);
}
Future<void> saveRefreshToken(String token) async => await _localStorage.save(
boxName: _boxName,
key: _refreshTokenKey,
value: token,
);
Future<String?> getAccessToken() async {
final box = Hive.box(_boxName);
return box.get(_accessTokenKey);
}
Future<String?> getAccessToken() async =>
await _localStorage.read(boxName: _boxName, key: _accessTokenKey);
Future<String?> getRefreshToken() async =>
await _localStorage.read(boxName: _boxName, key: _refreshTokenKey);
Future<void> deleteTokens() async => await _localStorage.clear(_boxName);
Future<String?> getRefreshToken() async {
final box = Hive.box(_boxName);
return box.get(_refreshTokenKey);
}
Future<void> deleteTokens() async {
final box = Hive.box(_boxName);
await box.delete(_accessTokenKey);
await box.delete(_refreshTokenKey);
}
}