feat : new method in token_storage_service.dart
use core local_repository
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:rasadyar_core/core.dart';
|
import 'package:rasadyar_core/core.dart';
|
||||||
import 'package:rasadyar_core/injection/di.dart';
|
import 'package:rasadyar_core/injection/di.dart';
|
||||||
|
|
||||||
@@ -23,36 +24,32 @@ class TokenStorageService extends GetxService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Hive.initFlutter();
|
await _localStorage.init();
|
||||||
await Hive.openBox(
|
await _localStorage.openBox(
|
||||||
_boxName,
|
_boxName,
|
||||||
encryptionCipher: HiveAesCipher(encryptionKey),
|
encryptionCipher: HiveAesCipher(encryptionKey),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveAccessToken(String token) async {
|
Future<void> saveAccessToken(String token) async => await _localStorage.save(
|
||||||
final box = Hive.box(_boxName);
|
boxName: _boxName,
|
||||||
await box.put(_accessTokenKey, token);
|
key: _accessTokenKey,
|
||||||
}
|
value: token,
|
||||||
|
);
|
||||||
|
|
||||||
Future<void> saveRefreshToken(String token) async {
|
Future<void> saveRefreshToken(String token) async => await _localStorage.save(
|
||||||
final box = Hive.box(_boxName);
|
boxName: _boxName,
|
||||||
await box.put(_refreshTokenKey, token);
|
key: _refreshTokenKey,
|
||||||
}
|
value: token,
|
||||||
|
);
|
||||||
|
|
||||||
Future<String?> getAccessToken() async {
|
Future<String?> getAccessToken() async =>
|
||||||
final box = Hive.box(_boxName);
|
await _localStorage.read(boxName: _boxName, key: _accessTokenKey);
|
||||||
return box.get(_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user