Загрузить файлы в «/»
This commit is contained in:
23
auth.js
Normal file
23
auth.js
Normal file
@@ -0,0 +1,23 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('auth-form');
|
||||
const errorEl = document.getElementById('auth-error');
|
||||
const isRegister = document.body.dataset.page === 'register';
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
errorEl.textContent = '';
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const endpoint = isRegister ? '/api/auth/register' : '/api/auth/login';
|
||||
|
||||
try {
|
||||
await API.request(endpoint, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
window.location.href = '/';
|
||||
} catch (err) {
|
||||
errorEl.textContent = err.message;
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user