please fix my code:<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f4f4f4;
        }

        #login-container {
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        #login-error {
            color: red;
            display: none;
        }
    </style>
</head>

<body>
    <div id="login-container">
        <h2>Admin Login</h2>
        <form id="login-form">
            <div>
                <label for="username">Email:</label>
                <input type="email" id="username" required>
            </div>
            <div>
                <label for="password">Password:</label>
                <input type="password" id="password" required>
            </div>
            <div id="login-error"></div>
            <button type="submit">Login</button>
        </form>
    </div>

    <div id="admin-content" style="display: none;">
        <h2>Admin Panel</h2>
        <form id="blog-form">
            <input type="text" id="title" placeholder="Post Title" required>
            <textarea id="md" placeholder="Post Content" required></textarea>
            <button type="submit">Add Post</button>
        </form>
        <div id="posts-section"></div>
    </div>

    <script>
        const loginForm = document.getElementById('login-form');
        const adminContent = document.getElementById('admin-content');
        const loginContainer = document.getElementById('login-container');
        const loginError = document.getElementById('login-error');
        const form = document.getElementById('blog-form');
        const postsSection = document.getElementById('posts-section');

        // Function to handle login
        loginForm.addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent default form submission

            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            // Authenticate the user
            const authResponse = await fetch('/api/auth', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ username, password }), // Send credentials
            });

            if (authResponse.ok) {
                loginContainer.style.display = 'none'; // Hide login form
                adminContent.style.display = 'block'; // Show admin content
                fetchPosts(); // Fetch existing posts
            } else {
                const errorData = await authResponse.json();
                loginError.textContent = errorData.error; // Display error message
                loginError.style.display = 'block';
            }
        });

        // Function to fetch posts
        async function fetchPosts() {
            const response = await fetch('/api/thread');
            const posts = await response.json();
            displayPosts(posts);
        }

        // Function to display posts
        function displayPosts(posts) {
            postsSection.innerHTML = ''; // Clear previous posts
            posts.forEach(post => {
                const postElement = document.createElement('div');
                postElement.innerHTML = `<h3>${post.title}</h3><p>${post.md}</p><small>${post.created}</small>`;
                postsSection.appendChild(postElement);
            });
        }

        // Handle adding a new post
        form.addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent default form submission

            const title = document.getElementById('title').value;
            const md = document.getElementById('md').value;

            const postResponse = await fetch('/api/add_post', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ title, md }), // Send post data
            });

            if (postResponse.ok) {
                fetchPosts(); // Refresh the posts list
                form.reset(); // Reset the form
            } else {
                const errorData = await postResponse.json();
                console.error('Error adding post:', errorData.error);
            }
        });
    </script>
</body>

</html>