fix: Retry socket authentication on auth failure

When socket authentication fails (e.g., race condition when token is not
yet loaded from storage), the client now retries authentication after
a short delay. This fixes the issue where:

- Login page shows spinning icon forever
- Playback fails with 'invalid token' errors
- Socket stays unauthenticated after transient failures

The fix adds a 500ms retry delay that allows time for the token to
become available (e.g., after hydration from localStorage).

Fixes #5101
This commit is contained in:
theluckystrike 2026-03-05 00:30:21 +07:00
parent 6d3404272c
commit 7ea0736111

View file

@ -143,6 +143,18 @@ export default {
authFailed(payload) { authFailed(payload) {
console.error('[SOCKET] auth failed', payload.message) console.error('[SOCKET] auth failed', payload.message)
this.isSocketAuthenticated = false this.isSocketAuthenticated = false
// Retry authentication after a short delay (e.g., token might not be loaded yet)
// This handles race conditions where socket connects before token is available
setTimeout(() => {
if (!this.isSocketAuthenticated && this.socket?.connected) {
const token = this.$store.getters['user/getToken']
if (token) {
console.log('[SOCKET] Retrying authentication after auth failure')
this.socket.emit('auth', token)
}
}
}, 500)
}, },
init(payload) { init(payload) {
console.log('Init Payload', payload) console.log('Init Payload', payload)