mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
fix auth log spam
This commit is contained in:
parent
7d4300c3e3
commit
0d91ef18c1
3 changed files with 50 additions and 6 deletions
|
|
@ -27,7 +27,20 @@ export class BufferSubscriptionService {
|
||||||
private isConnecting = false;
|
private isConnecting = false;
|
||||||
private messageQueue: Array<{ type: string; sessionId?: string }> = [];
|
private messageQueue: Array<{ type: string; sessionId?: string }> = [];
|
||||||
|
|
||||||
|
private initialized = false;
|
||||||
|
|
||||||
|
// biome-ignore lint/complexity/noUselessConstructor: This constructor documents the intentional design decision to not auto-connect
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Do not connect automatically - wait for initialize() to be called
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the buffer subscription service and connect to WebSocket
|
||||||
|
* Should be called after authentication is complete
|
||||||
|
*/
|
||||||
|
initialize() {
|
||||||
|
if (this.initialized) return;
|
||||||
|
this.initialized = true;
|
||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,6 +254,11 @@ export class BufferSubscriptionService {
|
||||||
* Returns an unsubscribe function
|
* Returns an unsubscribe function
|
||||||
*/
|
*/
|
||||||
subscribe(sessionId: string, handler: BufferUpdateHandler): () => void {
|
subscribe(sessionId: string, handler: BufferUpdateHandler): () => void {
|
||||||
|
// Ensure service is initialized when first subscription happens
|
||||||
|
if (!this.initialized) {
|
||||||
|
this.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
// Add handler to subscriptions
|
// Add handler to subscriptions
|
||||||
if (!this.subscriptions.has(sessionId)) {
|
if (!this.subscriptions.has(sessionId)) {
|
||||||
this.subscriptions.set(sessionId, new Set());
|
this.subscriptions.set(sessionId, new Set());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { PushNotificationPreferences, PushSubscription } from '../../shared/types.js';
|
import { PushNotificationPreferences, PushSubscription } from '../../shared/types.js';
|
||||||
import { createLogger } from '../utils/logger.js';
|
import { createLogger } from '../utils/logger.js';
|
||||||
|
import { authClient } from './auth-client.js';
|
||||||
|
|
||||||
// Re-export types for components
|
// Re-export types for components
|
||||||
export { PushSubscription, PushNotificationPreferences };
|
export { PushSubscription, PushNotificationPreferences };
|
||||||
|
|
@ -23,14 +24,30 @@ export class PushNotificationService {
|
||||||
private pushNotificationsAvailable = false;
|
private pushNotificationsAvailable = false;
|
||||||
private initializationPromise: Promise<void> | null = null;
|
private initializationPromise: Promise<void> | null = null;
|
||||||
|
|
||||||
|
// biome-ignore lint/complexity/noUselessConstructor: This constructor documents the intentional design decision to not auto-initialize
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initializationPromise = this.initialize().catch((error) => {
|
// Do not initialize automatically - wait for explicit initialization
|
||||||
logger.error('failed to initialize push notification service:', error);
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initialize(): Promise<void> {
|
/**
|
||||||
|
* Initialize the push notification service
|
||||||
|
* Should be called after authentication is complete
|
||||||
|
*/
|
||||||
|
async initialize(): Promise<void> {
|
||||||
|
if (this.initializationPromise) {
|
||||||
|
return this.initializationPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initializationPromise = this._initialize().catch((error) => {
|
||||||
|
logger.error('failed to initialize push notification service:', error);
|
||||||
|
// Don't throw here - just log the error
|
||||||
|
// Push notifications are optional functionality
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.initializationPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _initialize(): Promise<void> {
|
||||||
if (this.initialized) return;
|
if (this.initialized) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -468,7 +485,9 @@ export class PushNotificationService {
|
||||||
*/
|
*/
|
||||||
private async fetchVapidPublicKey(): Promise<void> {
|
private async fetchVapidPublicKey(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/push/vapid-public-key');
|
const response = await fetch('/api/push/vapid-public-key', {
|
||||||
|
headers: authClient.getAuthHeader(),
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 503) {
|
if (response.status === 503) {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,13 @@ async function sendToServer(level: keyof LogLevel, module: string, args: unknown
|
||||||
// Import authClient singleton dynamically to avoid circular dependencies
|
// Import authClient singleton dynamically to avoid circular dependencies
|
||||||
const { authClient } = await import('../services/auth-client.js');
|
const { authClient } = await import('../services/auth-client.js');
|
||||||
|
|
||||||
|
// Check if we have authentication before sending logs
|
||||||
|
const authHeader = authClient.getAuthHeader();
|
||||||
|
if (!authHeader.Authorization) {
|
||||||
|
// Skip sending logs if not authenticated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await fetch('/api/logs/client', {
|
await fetch('/api/logs/client', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue