mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
disable buffer subscriber until after we authenticated
This commit is contained in:
parent
6dfc1eb7f4
commit
eb0ce67b62
2 changed files with 43 additions and 6 deletions
|
|
@ -206,7 +206,7 @@ export class VibeTunnelApp extends LitElement {
|
||||||
console.log('🚀 Initializing services...');
|
console.log('🚀 Initializing services...');
|
||||||
try {
|
try {
|
||||||
// Initialize buffer subscription service for WebSocket connections
|
// Initialize buffer subscription service for WebSocket connections
|
||||||
bufferSubscriptionService.initialize();
|
await bufferSubscriptionService.initialize();
|
||||||
|
|
||||||
// Initialize push notification service
|
// Initialize push notification service
|
||||||
await pushNotificationService.initialize();
|
await pushNotificationService.initialize();
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ export class BufferSubscriptionService {
|
||||||
private messageQueue: Array<{ type: string; sessionId?: string }> = [];
|
private messageQueue: Array<{ type: string; sessionId?: string }> = [];
|
||||||
|
|
||||||
private initialized = false;
|
private initialized = false;
|
||||||
|
private noAuthMode: boolean | null = null;
|
||||||
|
|
||||||
// biome-ignore lint/complexity/noUselessConstructor: This constructor documents the intentional design decision to not auto-connect
|
// biome-ignore lint/complexity/noUselessConstructor: This constructor documents the intentional design decision to not auto-connect
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -38,10 +39,34 @@ export class BufferSubscriptionService {
|
||||||
* Initialize the buffer subscription service and connect to WebSocket
|
* Initialize the buffer subscription service and connect to WebSocket
|
||||||
* Should be called after authentication is complete
|
* Should be called after authentication is complete
|
||||||
*/
|
*/
|
||||||
initialize() {
|
async initialize() {
|
||||||
if (this.initialized) return;
|
if (this.initialized) return;
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
this.connect();
|
|
||||||
|
// Check no-auth mode
|
||||||
|
await this.checkNoAuthMode();
|
||||||
|
|
||||||
|
// Add a small delay to ensure auth token is fully loaded and verified
|
||||||
|
setTimeout(() => {
|
||||||
|
this.connect();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async checkNoAuthMode(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/auth/config');
|
||||||
|
if (response.ok) {
|
||||||
|
const config = await response.json();
|
||||||
|
this.noAuthMode = config.noAuth === true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn('Failed to check auth config:', error);
|
||||||
|
this.noAuthMode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isNoAuthMode(): boolean {
|
||||||
|
return this.noAuthMode === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private connect() {
|
private connect() {
|
||||||
|
|
@ -49,13 +74,25 @@ export class BufferSubscriptionService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isConnecting = true;
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
||||||
|
|
||||||
// Get auth token for WebSocket connection
|
// Get auth token for WebSocket connection
|
||||||
const currentUser = authClient.getCurrentUser();
|
const currentUser = authClient.getCurrentUser();
|
||||||
const token = currentUser?.token;
|
const token = currentUser?.token;
|
||||||
|
|
||||||
|
// Don't connect if we don't have a valid token (unless in no-auth mode)
|
||||||
|
if (!token && !this.isNoAuthMode()) {
|
||||||
|
logger.warn('No auth token available, postponing WebSocket connection');
|
||||||
|
// Retry connection after a delay
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.initialized && !this.ws) {
|
||||||
|
this.connect();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isConnecting = true;
|
||||||
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
|
||||||
// Build WebSocket URL with token as query parameter
|
// Build WebSocket URL with token as query parameter
|
||||||
let wsUrl = `${protocol}//${window.location.host}/buffers`;
|
let wsUrl = `${protocol}//${window.location.host}/buffers`;
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue