Fix JWT validation: use user_id instead of sub in socket servers, revert statusDriverLocation from toggleActive

This commit is contained in:
Hamza-Ayed
2026-08-01 17:57:47 +03:00
parent 1ddc6f8aa7
commit 77d7d9faf8
4 changed files with 3 additions and 6 deletions
@@ -387,7 +387,6 @@ class HomeCaptainController extends GetxController {
_checkFatigueBeforeOnline(); // Throws exception if tired _checkFatigueBeforeOnline(); // Throws exception if tired
if (double.parse(totalPoints) > minPointsThreshold) { if (double.parse(totalPoints) > minPointsThreshold) {
box.write(BoxName.statusDriverLocation, 'on');
locationController.startLocationUpdates(); locationController.startLocationUpdates();
HapticFeedback.heavyImpact(); HapticFeedback.heavyImpact();
activeStartTime = DateTime.now(); activeStartTime = DateTime.now();
@@ -412,7 +411,6 @@ class HomeCaptainController extends GetxController {
update(); update();
}); });
} else { } else {
box.write(BoxName.statusDriverLocation, 'off');
locationController.stopLocationUpdates(); locationController.stopLocationUpdates();
activeStartTime = null; activeStartTime = null;
activeTimer?.cancel(); activeTimer?.cancel();
@@ -427,7 +425,6 @@ class HomeCaptainController extends GetxController {
update(); update();
} }
} else { } else {
box.write(BoxName.statusDriverLocation, 'off');
locationController.stopLocationUpdates(); locationController.stopLocationUpdates();
activeStartTime = null; activeStartTime = null;
activeTimer?.cancel(); activeTimer?.cancel();
+1 -1
View File
@@ -731,7 +731,7 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
} else { } else {
$decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256')); $decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256'));
// Validate that the token belongs to this driver // Validate that the token belongs to this driver
if ((string)$decoded->sub !== (string)$driverId || $decoded->role !== 'driver') { if ((string)$decoded->user_id !== (string)$driverId || $decoded->role !== 'driver') {
logMsg("🚫 Connection Rejected: Invalid JWT for driver_id=$driverId"); logMsg("🚫 Connection Rejected: Invalid JWT for driver_id=$driverId");
$socket->disconnect(); $socket->disconnect();
return; return;
+1 -1
View File
@@ -209,7 +209,7 @@ $io->on('connection', function ($socket) {
socket_log("[WARNING] JWT Secret is not configured on the server!"); socket_log("[WARNING] JWT Secret is not configured on the server!");
} else { } else {
$decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256')); $decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256'));
if ((string)$decoded->sub !== (string)$passengerId || $decoded->role !== 'passenger') { if ((string)$decoded->user_id !== (string)$passengerId || $decoded->role !== 'passenger') {
socket_log("[SOCKET_REJECTED] Connection rejected: Invalid JWT for passenger_id=$passengerId from IP: $clientIp"); socket_log("[SOCKET_REJECTED] Connection rejected: Invalid JWT for passenger_id=$passengerId from IP: $clientIp");
$socket->disconnect(); $socket->disconnect();
return; return;
+1 -1
View File
@@ -221,7 +221,7 @@ $io->on('connection', function ($socket) {
socket_log("[WARNING] JWT Secret is not configured on the server!"); socket_log("[WARNING] JWT Secret is not configured on the server!");
} else { } else {
$decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256')); $decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256'));
if ((string)$decoded->sub !== (string)$passengerId || $decoded->role !== 'passenger') { if ((string)$decoded->user_id !== (string)$passengerId || $decoded->role !== 'passenger') {
socket_log("[SOCKET_REJECTED] Connection rejected: Invalid JWT for passenger_id=$passengerId from IP: $clientIp"); socket_log("[SOCKET_REJECTED] Connection rejected: Invalid JWT for passenger_id=$passengerId from IP: $clientIp");
$socket->disconnect(); $socket->disconnect();
return; return;