fixes lol

This commit is contained in:
doomtube 2026-01-09 02:37:31 -05:00
parent a206a606f7
commit 07b8e12197
10 changed files with 211 additions and 57 deletions

View file

@ -199,10 +199,8 @@ button:disabled {
}
.nav {
background: var(--bg-elevated);
border-bottom: 1px solid var(--border);
background: #000;
padding: 1rem 0;
margin-bottom: 2rem;
}
.nav-container {

View file

@ -200,10 +200,26 @@
return;
}
// Get token from localStorage if available (for authenticated users)
const token = typeof localStorage !== 'undefined' ? localStorage.getItem('token') : null;
console.log('Chat connecting with realmId:', realmId, token ? '(authenticated)' : '(guest)');
chatWebSocket.connect(realmId, token);
// Connect to chat - fetch fresh token if authenticated (uses httpOnly cookies)
(async () => {
let token = null;
try {
const response = await fetch('/api/auth/refresh', {
method: 'POST',
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
if (data.token) {
token = data.token;
}
}
} catch (e) {
// Not authenticated or refresh failed - connect as guest
}
console.log('Chat connecting with realmId:', realmId, token ? '(authenticated)' : '(guest)');
chatWebSocket.connect(realmId, token);
})();
// Function to scroll to newest messages (bottom for UP flow, top for DOWN flow)
const scrollToBottom = () => {

View file

@ -177,7 +177,22 @@
// Auto-connect to global chat on mount (like chat panel)
onMount(async () => {
const token = typeof localStorage !== 'undefined' ? localStorage.getItem('token') : null;
// Fetch fresh token if authenticated (uses httpOnly cookies)
let token = null;
try {
const response = await fetch('/api/auth/refresh', {
method: 'POST',
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
if (data.token) {
token = data.token;
}
}
} catch (e) {
// Not authenticated or refresh failed - connect as guest
}
// If already connected, just use that connection
if (isConnected) {

View file

@ -360,8 +360,22 @@ async function joinRealmChat(nameOrId, addSystemMessage, chatWebSocket, setRealm
// Add realm to filter
joinRealmFilter(targetRealmId);
// Get token for authenticated connection
const token = typeof localStorage !== 'undefined' ? localStorage.getItem('token') : null;
// Fetch fresh token if authenticated (uses httpOnly cookies)
let token = null;
try {
const response = await fetch('/api/auth/refresh', {
method: 'POST',
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
if (data.token) {
token = data.token;
}
}
} catch (e) {
// Not authenticated or refresh failed - connect as guest
}
// Connect to the realm's WebSocket
await chatWebSocket.connect(targetRealmId, token);

View file

@ -314,7 +314,6 @@
width: 100%;
aspect-ratio: 16 / 9;
background: #000;
border-radius: 8px;
overflow: hidden;
position: relative;
}

View file

@ -196,7 +196,7 @@ function createWatchSyncStore() {
}
}
function connect(realmId, token = null) {
async function connect(realmId, token = null) {
if (!browser) return;
if (ws?.readyState === WebSocket.OPEN && currentRealmId === realmId) return;
@ -208,8 +208,24 @@ function createWatchSyncStore() {
currentRealmId = realmId;
update(state => ({ ...state, loading: true, error: null }));
// Get token from localStorage if not provided
const authToken = token || localStorage.getItem('token');
// Fetch fresh token if not provided (uses httpOnly cookies)
let authToken = token;
if (!authToken) {
try {
const response = await fetch('/api/auth/refresh', {
method: 'POST',
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
if (data.token) {
authToken = data.token;
}
}
} catch (e) {
// Not authenticated or refresh failed - connect as guest
}
}
// Build WebSocket URL
let wsUrl = `${WS_URL.replace('/ws', '')}/watch/ws?realmId=${encodeURIComponent(realmId)}`;

View file

@ -98,7 +98,6 @@
.nav {
background: #000;
padding: var(--nav-padding-y) 0;
margin-bottom: var(--nav-margin-bottom);
}
.nav-container {

View file

@ -191,18 +191,8 @@
// Prevent duplicate skip calls
if (skipInProgress) return;
// Check if current video is locked (looped) - if so, let the server handle the restart
// The server will send a 'locked_restart' event to loop the video
const currentVid = $currentVideo;
if (currentVid?.isLocked) {
// Locked video - request sync to get the restart state from server
setTimeout(() => {
watchSync.requestSync();
}, 500);
return;
}
// When a video ends, skip to the next one (only for non-locked videos)
// When a video ends, call skip to advance to next (or restart if locked)
// The server handles locked videos by restarting them instead of advancing
if ($canControl) {
skipInProgress = true;
watchSync.skip();