From 8920ab447ef3ecacb589d1a04a6b888c3a0ca25c Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Tue, 9 Sep 2025 09:16:35 +0700 Subject: [PATCH] Update Dashboard, Result dan Sample Controller dengan JWT --- app/Config/Routes.php | 6 +++++- app/Controllers/Auth.php | 4 ++-- app/Controllers/Dashboard.php | 34 ++++++++++++++++++++++++++++++++++ app/Controllers/Result.php | 34 ++++++++++++++++++++++++++++++++++ app/Controllers/Sample.php | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 app/Controllers/Dashboard.php create mode 100644 app/Controllers/Result.php create mode 100644 app/Controllers/Sample.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 947945f..761efe3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -17,7 +17,11 @@ $routes->post('/api/v1/emr/lab/update-validasi', 'NUHATEMP::update'); $routes->post('/api/v1/emr/lab/detail', 'NUHATEMP::detail'); $routes->group('api', ['filter' => 'auth'], function($routes) { - $routes->get('coba-auth', 'Auth::coba'); + // $routes->get('coba-auth', 'Auth::coba'); + + $routes->get('dashboard', 'Dashboard::index'); + $routes->get('result', 'Result::index'); + $routes->get('sample', 'Sample::index'); }); $routes->post('/api/auth/login', 'Auth::login'); diff --git a/app/Controllers/Auth.php b/app/Controllers/Auth.php index 49832bf..442b6e9 100644 --- a/app/Controllers/Auth.php +++ b/app/Controllers/Auth.php @@ -98,7 +98,7 @@ class Auth extends Controller { } // Buat JWT payload - $exp = time() + 86400; + $exp = time() + 864000; $payload = [ 'userid' => $row['id'], 'roleid' => $row['role_id'], @@ -117,7 +117,7 @@ class Auth extends Controller { $this->response->setCookie([ 'name' => 'token', // nama token 'value' => $jwt, // value dari jwt yg sudah di hash - 'expire' => 86400, // 1 hari + 'expire' => 864000, // 10 hari 'path' => '/', // valid untuk semua path 'secure' => true, // set true kalau sudah HTTPS 'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript diff --git a/app/Controllers/Dashboard.php b/app/Controllers/Dashboard.php new file mode 100644 index 0000000..b9c1a4f --- /dev/null +++ b/app/Controllers/Dashboard.php @@ -0,0 +1,34 @@ +request->getCookie('token'); + $key = getenv('JWT_SECRET'); + + // Decode Token dengan Key yg ada di .env + $decodedPayload = JWT::decode($token, new Key($key, 'HS256')); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Authenticated', + 'data' => $decodedPayload + ], 200); + } + +} diff --git a/app/Controllers/Result.php b/app/Controllers/Result.php new file mode 100644 index 0000000..a906d6a --- /dev/null +++ b/app/Controllers/Result.php @@ -0,0 +1,34 @@ +request->getCookie('token'); + $key = getenv('JWT_SECRET'); + + // Decode Token dengan Key yg ada di .env + $decodedPayload = JWT::decode($token, new Key($key, 'HS256')); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Authenticated', + 'data' => $decodedPayload + ], 200); + } + +} diff --git a/app/Controllers/Sample.php b/app/Controllers/Sample.php new file mode 100644 index 0000000..0ba1b58 --- /dev/null +++ b/app/Controllers/Sample.php @@ -0,0 +1,34 @@ +request->getCookie('token'); + $key = getenv('JWT_SECRET'); + + // Decode Token dengan Key yg ada di .env + $decodedPayload = JWT::decode($token, new Key($key, 'HS256')); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Authenticated', + 'data' => $decodedPayload + ], 200); + } + +}