Initial commit: Retribusi frontend dengan dashboard, event logs, dan settings
This commit is contained in:
45
api/auth/login.php.example
Normal file
45
api/auth/login.php.example
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* EXAMPLE: Login Endpoint dengan CORS Handler
|
||||
*
|
||||
* INSTRUKSI:
|
||||
* 1. Copy kode CORS handler ke paling atas (sebelum require/include apapun)
|
||||
* 2. Pastikan CORS handler dieksekusi SEBELUM logic auth
|
||||
* 3. Jangan ubah response bisnis API, hanya tambahkan CORS
|
||||
*/
|
||||
|
||||
// ================= CORS HANDLER (WAJIB PALING ATAS) =================
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-API-KEY");
|
||||
|
||||
// Handle preflight OPTIONS request
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit;
|
||||
}
|
||||
// ================= END CORS HANDLER =================
|
||||
|
||||
// Setelah CORS handler, baru require/include file lain
|
||||
// require_once '../config/database.php';
|
||||
// require_once '../config/auth.php';
|
||||
|
||||
// Set header untuk JSON response
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Logic auth/login di sini
|
||||
// ... kode login yang sudah ada ...
|
||||
|
||||
// Example response (sesuaikan dengan logic yang sudah ada)
|
||||
/*
|
||||
$response = [
|
||||
'token' => 'Bearer xxxxx',
|
||||
'user' => [
|
||||
'username' => 'admin',
|
||||
'role' => 'admin',
|
||||
'locations' => ['kerkof_01']
|
||||
]
|
||||
];
|
||||
echo json_encode($response);
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user