import { getListingSubscribers, getSubscriptionsByUser } from './queries'; // Import the getListingSubscribers function
//Skipping a bunch of unrelated code...
socket.on('userAuthenticated', async () => {
console.log('User authenticated:', username);
// Check if the user is authenticated before trying to rejoin rooms
if (socket.data.user) {
try {
//TODO There is an error here. context.user doesn't exist and so we can't fetch subscriptions here.
// It's all happening before the user is fully authenticated apparently.
const subscriptions = await getSubscriptionsByUser(undefined, context);
subscriptions.forEach(sub => {
const room = `listing_${sub.listingId}`;
socket.join(room);
console.log(`${username} rejoined room ${room}`);
});
} catch (error) {
console.error('Error rejoining rooms:', error);
}
} else {
console.warn('User not authenticated, skipping room rejoining.');
}
});
import { getListingSubscribers, getSubscriptionsByUser } from './queries'; // Import the getListingSubscribers function
//Skipping a bunch of unrelated code...
socket.on('userAuthenticated', async () => {
console.log('User authenticated:', username);
// Check if the user is authenticated before trying to rejoin rooms
if (socket.data.user) {
try {
//TODO There is an error here. context.user doesn't exist and so we can't fetch subscriptions here.
// It's all happening before the user is fully authenticated apparently.
const subscriptions = await getSubscriptionsByUser(undefined, context);
subscriptions.forEach(sub => {
const room = `listing_${sub.listingId}`;
socket.join(room);
console.log(`${username} rejoined room ${room}`);
});
} catch (error) {
console.error('Error rejoining rooms:', error);
}
} else {
console.warn('User not authenticated, skipping room rejoining.');
}
});