import { sendFormAsync } from "./shared.js"; async function redirectIfAlreadySignedIn() { const response = await fetch('/api/v1/auth/me', { method: 'GET', credentials: 'same-origin' }); if (response.ok) { window.location.replace('/dashboard'); } } function togglePassword() { const passwordInput = document.getElementById('password'); const newInputType = passwordInput.type === 'password' ? 'text' : 'password'; passwordInput.type = newInputType; } async function submitLoginForm(){ const form = document.getElementById('loginForm'); await sendFormAsync(form); } const togglePasswordButton = document.getElementById('togglePassword'); togglePasswordButton.addEventListener('click', togglePassword); const loginForm = document.getElementById('loginForm'); loginForm.addEventListener('submit', async (event) => { event.preventDefault(); // Prevent the default form submission await submitLoginForm(); }); await redirectIfAlreadySignedIn();