first commit
This commit is contained in:
23
backend/logout.php
Normal file
23
backend/logout.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// logout.php — تسجيل الخروج الآمن وإلغاء التوكن
|
||||
|
||||
require_once __DIR__ . '/connect.php';
|
||||
|
||||
try {
|
||||
$jwtService = new JwtService($redis);
|
||||
$decoded = $jwtService->authenticate();
|
||||
|
||||
$jti = $decoded->jti ?? null;
|
||||
$exp = $decoded->exp ?? 0;
|
||||
$remaining = $exp - time();
|
||||
|
||||
if ($jti && $remaining > 0) {
|
||||
$jwtService->revokeToken($jti, $remaining);
|
||||
securityLog("User logged out and token revoked", ['user_id' => $decoded->user_id, 'jti' => $jti]);
|
||||
}
|
||||
|
||||
jsonSuccess(null, "Logged out successfully");
|
||||
|
||||
} catch (Exception $e) {
|
||||
jsonError("Logout failed", 500);
|
||||
}
|
||||
Reference in New Issue
Block a user