28 lines
801 B
JavaScript
28 lines
801 B
JavaScript
// Copyright © 2026 Olaf Kolkman
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
const form = document.querySelector('#login-form');
|
|
const status = document.querySelector('#login-status');
|
|
|
|
form.addEventListener('submit', async (event) => {
|
|
event.preventDefault();
|
|
status.textContent = 'Signing in...';
|
|
status.style.color = '#334155';
|
|
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(Object.fromEntries(new FormData(form))),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
status.textContent = 'Sign-in failed.';
|
|
status.style.color = '#b91c1c';
|
|
return;
|
|
}
|
|
|
|
const data = await response.json();
|
|
localStorage.setItem('linklogAccessToken', data.access_token);
|
|
window.location.assign('/profile');
|
|
});
|