<!DOCTYPE html>
<html>
<head>
    <title>Callback</title>
    <script>
        window.onload = function() {
            // Ambil URL fragment yang berisi access token
            const hash = window.location.hash.substring(1);
            const params = new URLSearchParams(hash);

            const accessToken = params.get('access_token');
            const tokenType = params.get('token_type');
            const expiresIn = params.get('expires_in');

            // Debug output
            console.log('Hash:', hash);
            console.log('Access Token:', accessToken);
            console.log('Token Type:', tokenType);
            console.log('Expires In:', expiresIn);

            if (accessToken) {
                // Simpan access token di session storage atau local storage
                sessionStorage.setItem('access_token', accessToken);
                sessionStorage.setItem('token_type', tokenType);
                sessionStorage.setItem('expires_in', expiresIn);

                // Redirect ke halaman sukses atau langkah berikutnya
                window.location.href = 'success_page.php';
            } else {
                document.getElementById('error').textContent = 'Error: Access token tidak ditemukan.';
            }
        };
    </script>
</head>
<body>
    <h1>Callback</h1>
    <p id="error">Menunggu otorisasi...</p>
</body>
</html>
