Update: 2026-06-26 04:04:03

This commit is contained in:
Hamza-Ayed
2026-06-26 04:04:04 +03:00
parent aea0c8e44e
commit da9e6eb981
10 changed files with 325 additions and 112 deletions

View File

@@ -65,13 +65,21 @@ class FirebaseMessagesController extends GetxController {
// : Get.put(NotificationController());
Future getToken() async {
fcmToken.getToken().then((token) {
// Log.print('fcmToken: ${token}');
box.write(BoxName.tokenFCM, (token.toString()));
});
// 🔹 الاشتراك في topic
await fcmToken.subscribeToTopic("service"); // أو "users" حسب نوع المستخدم
Log.print("Subscribed to 'service' topic ✅");
try {
final token = await fcmToken.getToken();
if (token != null) {
box.write(BoxName.tokenFCM, token);
}
} catch (e) {
Log.print('⚠️ getToken error (APNS not ready yet): $e');
}
try {
await fcmToken.subscribeToTopic("service");
Log.print("Subscribed to 'service' topic ✅");
} catch (e) {
Log.print('⚠️ subscribeToTopic error (APNS not ready yet): $e');
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// If the app is in the background or terminated, show a system tray message

View File

@@ -221,7 +221,6 @@ class CRUD {
}
if (sc == 401) {
// استخدام SessionManager لتجديد الجلسة عند 401
if (Get.isRegistered<SessionManager>()) {
final sessionManager = Get.find<SessionManager>();
if (!sessionManager.isRefreshing.value &&
@@ -229,7 +228,6 @@ class CRUD {
await sessionManager.refreshSession(silent: false);
}
} else {
// fallback للتجديد القديم
await getJWT();
}
return 'token_expired';
@@ -262,12 +260,10 @@ class CRUD {
if (Get.isRegistered<SessionManager>()) {
final sessionManager = Get.find<SessionManager>();
await sessionManager.refreshSession(silent: true);
token = r(box.read(BoxName.jwt) ?? '').toString().split(Env.addd)[0];
} else {
// fallback: تجديد يدوي
await getJWT();
token = r(box.read(BoxName.jwt) ?? '').toString().split(Env.addd)[0];
}
token = r(box.read(BoxName.jwt) ?? '').toString().split(Env.addd)[0];
}
// Initialize app signature if null
@@ -302,7 +298,7 @@ class CRUD {
// ═══════════════════════════════════════════════════════════════
// getJWT — V1 Login Flow
// ═══════════════════════════════════════════════════════════════
Future<void> getJWT() async {
Future<bool> getJWT() async {
var payload = {
'fingerprint': _getFpHeader(),
'password': box.read(BoxName.password) ?? '',
@@ -310,7 +306,6 @@ class CRUD {
'aud': 'service',
};
// Initialize app signature if null
if (_appSignature == null) {
try {
_appSignature = await SecurityHelper.getAppSignature();
@@ -340,10 +335,11 @@ class CRUD {
await storage.write(key: BoxName.jwt, value: c(jwt));
if (hmac != null) {
await box.write(BoxName.hmac, hmac);
final verify = box.read(BoxName.hmac);
Log.print('✅ Verified stored HMAC: $verify');
}
return true;
}
Log.print('❌ getJWT failed: $response');
return false;
}
// ─────────────────────────────────────────────────────────────

View File

@@ -79,18 +79,12 @@ class SessionManager extends GetxController {
for (int attempt = 1; attempt <= _maxRetries; attempt++) {
Log.print('🔄 Session refresh attempt $attempt/$_maxRetries');
await CRUD().getJWT();
final success = await CRUD().getJWT();
// التحقق من نجاح التجديد
final newRawToken = box.read(BoxName.jwt)?.toString() ?? '';
final newToken = newRawToken.isNotEmpty ? r(newRawToken).toString().split(Env.addd)[0] : '';
final isValid = CRUD.isJwtValid(newToken);
if (isValid) {
if (success) {
status.value = SessionStatus.valid;
isRefreshing.value = false;
// إشعار النجاح
if (!silent) {
_showSessionRefreshedNotification();
}
@@ -99,7 +93,6 @@ class SessionManager extends GetxController {
return true;
}
// إذا فشلت المحاولة، انتظر قبل إعادة المحاولة
if (attempt < _maxRetries) {
await Future.delayed(Duration(seconds: attempt));
}