Testing JWT Untuk Routes tertentu

This commit is contained in:
mikael-zakaria 2025-09-04 09:42:30 +07:00
parent 2af6fb474f
commit 6ae72a6bb1
3 changed files with 21 additions and 8 deletions

View File

@ -71,7 +71,7 @@ class Filters extends BaseFilters
*/
public array $globals = [
'before' => [
// 'auth',
'auth',
'cors',
// 'honeypot',
// 'csrf',

View File

@ -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');

View File

@ -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);
}
}