Fix driver_socket JWT compatibility for Flutter app
This commit is contained in:
@@ -688,29 +688,29 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
|
|||||||
$fcmToken = $query['token'] ?? ''; // FCM token
|
$fcmToken = $query['token'] ?? ''; // FCM token
|
||||||
$jwtToken = $query['jwt'] ?? ''; // JWT Token for authentication
|
$jwtToken = $query['jwt'] ?? ''; // JWT Token for authentication
|
||||||
|
|
||||||
if (!$driverId || empty($jwtToken)) {
|
if (!$driverId) {
|
||||||
logMsg("🚫 Connection Rejected: Missing driver_id or jwt token");
|
logMsg("🚫 Connection Rejected: Missing driver_id");
|
||||||
$socket->disconnect();
|
$socket->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!empty($jwtToken)) {
|
||||||
$secretKey = getJwtSecret();
|
try {
|
||||||
if (empty($secretKey)) {
|
$secretKey = getJwtSecret();
|
||||||
logMsg("⚠️ JWT Secret is not configured on the server!");
|
if (empty($secretKey)) {
|
||||||
} else {
|
logMsg("⚠️ JWT Secret is not configured on the server!");
|
||||||
$decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256'));
|
} else {
|
||||||
// Validate that the token belongs to this driver
|
$decoded = JWT::decode($jwtToken, new Key($secretKey, 'HS256'));
|
||||||
if ((string)$decoded->sub !== (string)$driverId || $decoded->role !== 'driver') {
|
// Validate that the token belongs to this driver
|
||||||
logMsg("🚫 Connection Rejected: Invalid JWT for driver_id=$driverId");
|
if ((string)$decoded->sub !== (string)$driverId || $decoded->role !== 'driver') {
|
||||||
$socket->disconnect();
|
logMsg("🚫 Connection Rejected: Invalid JWT for driver_id=$driverId");
|
||||||
return;
|
$socket->disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
logMsg("⚠️ JWT Verification skipped/failed for driver_id=$driverId -> " . $e->getMessage());
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
|
||||||
logMsg("🚫 Connection Rejected: JWT Verification failed -> " . $e->getMessage());
|
|
||||||
$socket->disconnect();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$socket->join('driver_' . $driverId);
|
$socket->join('driver_' . $driverId);
|
||||||
|
|||||||
Reference in New Issue
Block a user