🪻 distributed transcription service thistle.dunkirk.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: skip canceled subscriptions on delete

+26 -7
+13 -3
src/index.ts
··· 145 145 return; 146 146 } 147 147 148 - // Update each subscription in the database 149 - for (const subscription of subscriptions.result.items) { 148 + // Filter to only active/trialing/past_due subscriptions (not canceled/expired) 149 + const currentSubscriptions = subscriptions.result.items.filter( 150 + (sub) => sub.status === 'active' || sub.status === 'trialing' || sub.status === 'past_due' 151 + ); 152 + 153 + if (currentSubscriptions.length === 0) { 154 + console.log(`[Sync] No current subscriptions found for customer ${customer.id}`); 155 + return; 156 + } 157 + 158 + // Update each current subscription in the database 159 + for (const subscription of currentSubscriptions) { 150 160 db.run( 151 161 `INSERT INTO subscriptions (id, user_id, customer_id, status, current_period_start, current_period_end, cancel_at_period_end, canceled_at, updated_at) 152 162 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ··· 183 193 } 184 194 185 195 console.log( 186 - `[Sync] Linked ${subscriptions.result.items.length} subscription(s) to user ${userId} (${email})`, 196 + `[Sync] Linked ${currentSubscriptions.length} current subscription(s) to user ${userId} (${email})`, 187 197 ); 188 198 } catch (error) { 189 199 console.error(
+13 -4
src/lib/auth.ts
··· 190 190 191 191 // Get user's subscription if they have one 192 192 const subscription = db 193 - .query<{ id: string }, [number]>( 194 - "SELECT id FROM subscriptions WHERE user_id = ? ORDER BY created_at DESC LIMIT 1", 193 + .query<{ id: string; status: string; cancel_at_period_end: number }, [number]>( 194 + "SELECT id, status, cancel_at_period_end FROM subscriptions WHERE user_id = ? ORDER BY created_at DESC LIMIT 1", 195 195 ) 196 196 .get(userId); 197 197 198 - // Cancel subscription if it exists (soft cancel - keeps access until period end) 199 - if (subscription) { 198 + // Cancel subscription if it exists and is not already canceled or scheduled to cancel 199 + if ( 200 + subscription && 201 + subscription.status !== 'canceled' && 202 + subscription.status !== 'expired' && 203 + !subscription.cancel_at_period_end 204 + ) { 200 205 try { 201 206 const { polar } = await import("./polar"); 202 207 await polar.subscriptions.update({ ··· 213 218 ); 214 219 // Continue with user deletion even if subscription cancellation fails 215 220 } 221 + } else if (subscription) { 222 + console.log( 223 + `[User Delete] Skipping cancellation for subscription ${subscription.id} (status: ${subscription.status}, cancel_at_period_end: ${subscription.cancel_at_period_end})`, 224 + ); 216 225 } 217 226 218 227 // Reassign class transcriptions to ghost user (id=0)