2026-06-14 11:58:04 +02:00

39 lines
1.3 KiB
JavaScript

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 togglePasswordButton = document.getElementById('togglePassword');
const newInputType = passwordInput.type === 'password' ? 'text' : 'password';
passwordInput.type = newInputType;
const isVisible = newInputType === 'text';
togglePasswordButton.textContent = isVisible ? 'Hide' : 'Show';
togglePasswordButton.setAttribute('aria-pressed', String(isVisible));
}
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();