remake apis 0.151
This commit is contained in:
@@ -1,29 +1,23 @@
|
||||
function getToken() {
|
||||
return localStorage.getItem("token") || sessionStorage.getItem("token");
|
||||
}
|
||||
|
||||
function tokenCheck() {
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
window.location.href = "https://ru.homyk.space";
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
tokenCheck();
|
||||
|
||||
document.getElementById('logoutForm').addEventListener('submit', function(e) {
|
||||
// Проверка авторизации через cookie
|
||||
fetch('/api/verify', { credentials: 'include' })
|
||||
.then(r => { if (!r.ok) window.location.href = '/'; })
|
||||
.catch(() => { window.location.href = '/'; });
|
||||
|
||||
// Logout — удаляем cookie на бэкенде
|
||||
document.getElementById('logoutForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem("token");
|
||||
sessionStorage.removeItem("token");
|
||||
tokenCheck();
|
||||
await fetch('/api/logout', {
|
||||
method: 'POST',
|
||||
credentials: 'include'
|
||||
});
|
||||
window.location.href = '/';
|
||||
});
|
||||
|
||||
document.querySelector(".form-info").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const token = getToken();
|
||||
|
||||
const guestData = {
|
||||
name: document.getElementById('ffname').value || "",
|
||||
middlename: document.getElementById('fmname').value || "",
|
||||
@@ -36,15 +30,11 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
.join(', ')
|
||||
};
|
||||
|
||||
console.log(guestData);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include', // ← токен идёт через cookie
|
||||
body: JSON.stringify(guestData)
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user