[Fix] Websocket Tokens Refresh issue (#944)

* - Temporary fix for token refresh issue.

More testing is needed.

* Update server-console.blade.php

Removal of final old token var (no longer needed as livewire will handle it through piping)
This commit is contained in:
Alexander Featherson 2025-01-25 16:29:01 -05:00 committed by GitHub
parent 654143addc
commit 401026efa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 11 deletions

View File

@ -103,6 +103,12 @@ class ServerConsole extends Widget
} }
} }
#[On('token-request')]
public function tokenRequest(): void
{
$this->dispatch('sendAuthRequest', token: $this->getToken());
}
#[On('store-stats')] #[On('store-stats')]
public function storeStats(string $data): void public function storeStats(string $data): void
{ {

View File

@ -113,7 +113,6 @@
terminal.writeln(TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m'); terminal.writeln(TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m');
const socket = new WebSocket("{{ $this->getSocket() }}"); const socket = new WebSocket("{{ $this->getSocket() }}");
let token = '{{ $this->getToken() }}';
socket.onerror = (event) => { socket.onerror = (event) => {
$wire.dispatchSelf('websocket-error'); $wire.dispatchSelf('websocket-error');
@ -149,21 +148,13 @@
break; break;
case 'token expiring': case 'token expiring':
case 'token expired': case 'token expired':
token = '{{ $this->getToken() }}'; $wire.dispatchSelf('token-request');
socket.send(JSON.stringify({
'event': 'auth',
'args': [token]
}));
break; break;
} }
}; };
socket.onopen = (event) => { socket.onopen = (event) => {
socket.send(JSON.stringify({ $wire.dispatchSelf('token-request');
'event': 'auth',
'args': [token]
}));
}; };
Livewire.on('setServerState', ({ state, uuid }) => { Livewire.on('setServerState', ({ state, uuid }) => {
@ -178,6 +169,13 @@
})); }));
}); });
$wire.on('sendAuthRequest', ({ token }) => {
socket.send(JSON.stringify({
'event': 'auth',
'args': [token]
}));
});
$wire.on('sendServerCommand', ({ command }) => { $wire.on('sendServerCommand', ({ command }) => {
socket.send(JSON.stringify({ socket.send(JSON.stringify({
'event': 'send command', 'event': 'send command',