🪻 distributed transcription service thistle.dunkirk.sh
1
fork

Configure Feed

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

chore: sync account deletion and subscription cancelation

+28 -4
+3 -3
src/index.ts
··· 494 494 }, 495 495 }, 496 496 "/api/user": { 497 - DELETE: (req) => { 497 + DELETE: async (req) => { 498 498 const sessionId = getSessionFromRequest(req); 499 499 if (!sessionId) { 500 500 return Response.json({ error: "Not authenticated" }, { status: 401 }); ··· 510 510 }); 511 511 if (rateLimitError) return rateLimitError; 512 512 513 - deleteUser(user.id); 513 + await deleteUser(user.id); 514 514 return Response.json( 515 515 { success: true }, 516 516 { ··· 1402 1402 if (Number.isNaN(userId)) { 1403 1403 return Response.json({ error: "Invalid user ID" }, { status: 400 }); 1404 1404 } 1405 - deleteUser(userId); 1405 + await deleteUser(userId); 1406 1406 return Response.json({ success: true }); 1407 1407 } catch (error) { 1408 1408 return handleError(error);
+25 -1
src/lib/auth.ts
··· 182 182 return match?.[1] ?? null; 183 183 } 184 184 185 - export function deleteUser(userId: number): void { 185 + export async function deleteUser(userId: number): Promise<void> { 186 + // Get user's subscription if they have one 187 + const subscription = db 188 + .query<{ id: string }, [number]>( 189 + "SELECT id FROM subscriptions WHERE user_id = ? ORDER BY created_at DESC LIMIT 1", 190 + ) 191 + .get(userId); 192 + 193 + // Revoke subscription if it exists 194 + if (subscription) { 195 + try { 196 + const { polar } = await import("./polar"); 197 + await polar.subscriptions.revoke({ id: subscription.id }); 198 + console.log( 199 + `[User Delete] Revoked subscription ${subscription.id} for user ${userId}`, 200 + ); 201 + } catch (error) { 202 + console.error( 203 + `[User Delete] Failed to revoke subscription ${subscription.id}:`, 204 + error, 205 + ); 206 + // Continue with user deletion even if subscription revocation fails 207 + } 208 + } 209 + 186 210 db.run("DELETE FROM users WHERE id = ?", [userId]); 187 211 } 188 212