Spaces:
Sleeping
Sleeping
Nathan commited on
Commit ·
cd4f86d
1
Parent(s): 092070c
Fix: Settings saving and stats loading for multi-channel users
Browse files293 unmodified lines29429529629729729829930030167 unmodified lines369370371371372372373374375376377377378379380379381382383384293 unmodified lines// --- Dashboard API ---
app.get('/api/stats', authenticateToken, async (req, res) => { // Use limit(1) instead of single() to avoid crash with multiple channels const { data: channel } = await db.from('channels').select('niche, preferred_hours, custom_client_id, custom_client_secret, total_views, subscribers').eq('user_id', req.userId).single(); const { data: channel } = await db.from('channels').select('niche, preferred_hours, custom_client_id, custom_client_secret, total_views, subscribers').eq('user_id', req.userId).limit(1).maybeSingle(); const { count: videosGenerated } = await db.from('activity').select('*', { count: 'exact', head: true }).eq('user_id', req.userId).eq('type', 'VIDEO_PUBLISHED'); res.json({67 unmodified linesapp.post('/api/settings', authenticateToken, async (req, res) => { const { niche, preferred_hours, custom_client_id, custom_client_secret } = req.body; try { const { error } = await db.from('channels').upsert({ user_id: req.userId, // Update ALL channels for this user with these settings const { error } = await db.from('channels').update({ niche, preferred_hours, custom_client_id, custom_client_secret }, { onConflict: 'user_id' }); }).eq('user_id', req.userId);
if (error) { console.error('❌ Supabase Upsert Error:', error); console.error('❌ Supabase Update Error:', error); throw error; } res.json({ success: true });server.js+7-5