diff --git a/app/Config/Filters.php b/app/Config/Filters.php index fe57dcb..5ee9cb1 100644 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -71,7 +71,7 @@ class Filters extends BaseFilters */ public array $globals = [ 'before' => [ - // 'auth', + 'auth', 'cors', // 'honeypot', // 'csrf', diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a5f9802..a779411 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -16,15 +16,15 @@ $routes->post('/api/v1/emr/lab/insert', 'NUHATEMP::create'); $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->post('/api/coba-auth', 'Auth::coba'); - +$routes->group('api', ['filter' => 'auth'], function($routes) { + $routes->get('coba-auth', 'Auth::coba'); +}); $routes->post('/api/auth/login', 'Auth::login'); $routes->post('/api/auth/change_pass', 'Auth::change_pass'); $routes->post('/api/auth/register', 'Auth::register'); $routes->get('/api/auth/check', 'Auth::checkAuth'); $routes->post('/api/auth/logout', 'Auth::logout'); -// }); + $routes->get('/api/patient', 'Patient::index'); $routes->post('/api/patient', 'Patient::create'); diff --git a/app/Controllers/Auth.php b/app/Controllers/Auth.php index 6b1547b..bede8b8 100644 --- a/app/Controllers/Auth.php +++ b/app/Controllers/Auth.php @@ -208,10 +208,23 @@ class Auth extends Controller { // } public function coba() { + + $token = $this->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', - 'message' => 'Already Login' - ],200); + 'status' => 'success', + 'message' => 'Authenticated', + 'data' => $decodedPayload + ], 200); + + // return $this->respond([ + // 'status' => 'success', + // 'message' => 'Already Login' + // ],200); } }