Authenticate browser media with durable HttpOnly login cookies

Adapted cookie, origin, URL validation and secret handling from MikaelKW/nodecast-tv-plus. Protect API roles, revoke logins across restart, preserve existing accounts, and isolate transcode sessions by account.

Co-authored-by: Mikael <mikaelkwessel@gmail.com>
This commit is contained in:
Technomancer702
2026-10-12 16:53:15 -07:00
parent 2999d6542f
commit 1f665dcb11
24 changed files with 553 additions and 111 deletions

View File

@ -9,17 +9,12 @@ const API = {
async request(method, endpoint, data = null) {
const options = {
method,
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
}
};
// Add authentication token if available
const token = localStorage.getItem('authToken');
if (token) {
options.headers['Authorization'] = `Bearer ${token}`;
}
if (data) {
options.body = JSON.stringify(data);
}
@ -40,7 +35,7 @@ const API = {
if (response.status === 401) {
localStorage.removeItem('authToken');
window.location.href = '/login.html';
return;
throw new Error('Authentication required');
}
throw new Error(result.error || `Server responded with ${response.status}`);
}