Perbaikan Auth
This commit is contained in:
parent
eb883cf059
commit
f64b5d1bc9
@ -112,16 +112,24 @@ class Auth extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
|
// 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([
|
$this->response->setCookie([
|
||||||
'name' => 'token', // nama token
|
// 'name' => 'token', // nama token
|
||||||
'value' => $jwt, // value dari jwt yg sudah di hash
|
// 'value' => $jwt, // value dari jwt yg sudah di hash
|
||||||
'expire' => 864000, // 10 hari
|
// 'expire' => 864000, // 10 hari
|
||||||
'path' => '/', // valid untuk semua path
|
// 'path' => '/', // valid untuk semua path
|
||||||
'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
|
// 'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
|
||||||
'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
// 'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
||||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
// '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
|
// Response tanpa token di body
|
||||||
return $this->respond([
|
return $this->respond([
|
||||||
@ -134,7 +142,7 @@ class Auth extends Controller {
|
|||||||
// ok
|
// ok
|
||||||
public function logout() {
|
public function logout() {
|
||||||
// Definisikan ini pada cookies browser, harus sama dengan cookies login
|
// 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([
|
return $this->response->setCookie([
|
||||||
'name' => 'token',
|
'name' => 'token',
|
||||||
'value' => '',
|
'value' => '',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user