fix : change app architecture

feat : add some method to local storage
This commit is contained in:
2025-05-14 09:42:44 +03:30
parent e11ef1990c
commit feb3df6a06
50 changed files with 1007 additions and 70 deletions

View File

@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
import '../../presentation/routes/pages.dart';
class AuthMiddleware extends GetMiddleware{
@override
RouteSettings? redirect(String? route) {
if(route == AuthPaths.auth) {
return const RouteSettings(name: AuthPaths.moduleList);
}
return super.redirect(route);
}
}

View File

@@ -0,0 +1,9 @@
import 'package:rasadyar_core/core.dart';
class AuthService extends GetxService{
Future<void> initService() async {
}
}

View File

@@ -0,0 +1,59 @@
import 'dart:convert';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/injection/di.dart';
class TokenStorageService extends GetxService {
static const String _boxName = 'secureBox';
static const String _accessTokenKey = 'accessToken';
static const String _refreshTokenKey = 'refreshToken';
final FlutterSecureStorage _secureStorage = FlutterSecureStorage();
final HiveLocalStorage _localStorage = diCore.get<HiveLocalStorage>();
Future<void> init() async {
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
final encryptionKey =
encryptedKey != null
? base64Url.decode(encryptedKey)
: Hive.generateSecureKey();
if (encryptedKey == null) {
await _secureStorage.write(
key: 'hive_enc_key',
value: base64UrlEncode(encryptionKey),
);
}
await Hive.initFlutter();
await Hive.openBox(
_boxName,
encryptionCipher: HiveAesCipher(encryptionKey),
);
}
Future<void> saveAccessToken(String token) async {
final box = Hive.box(_boxName);
await box.put(_accessTokenKey, token);
}
Future<void> saveRefreshToken(String token) async {
final box = Hive.box(_boxName);
await box.put(_refreshTokenKey, token);
}
Future<String?> getAccessToken() async {
final box = Hive.box(_boxName);
return box.get(_accessTokenKey);
}
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);
}
}