Perbaikan Auth

This commit is contained in:
mahdahar 2025-12-30 09:08:58 +07:00
parent eb883cf059
commit f64b5d1bc9

View File

@ -112,16 +112,24 @@ class Auth extends Controller {
}
// Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
// $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
$this->response->setCookie([
'name' => 'token', // nama token
'value' => $jwt, // value dari jwt yg sudah di hash
'expire' => 864000, // 10 hari
'path' => '/', // valid untuk semua path
'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
// 'name' => 'token', // nama token
// 'value' => $jwt, // value dari jwt yg sudah di hash
// 'expire' => 864000, // 10 hari
// 'path' => '/', // valid untuk semua path
// 'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
// 'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
// 'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
'name' => 'token',
'value' => '',
'expire' => time() - 3600,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => Cookie::SAMESITE_NONE
]);
// Response tanpa token di body
return $this->respond([
@ -134,7 +142,7 @@ class Auth extends Controller {
// ok
public function logout() {
// Definisikan ini pada cookies browser, harus sama dengan cookies login
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
// $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
return $this->response->setCookie([
'name' => 'token',
'value' => '',