Fix account deletion flow

This commit is contained in:
gpt-engineer-app[bot]
2025-10-29 22:46:49 +00:00
parent 2918f9d280
commit a2cb037410
8 changed files with 143 additions and 28 deletions

View File

@@ -52,23 +52,31 @@ serve(async (req) => {
userId: user.id
});
// Check for existing pending deletion request
// Check for existing active deletion request (pending or confirmed)
const { data: existingRequest } = await supabaseClient
.from('account_deletion_requests')
.select('*')
.eq('user_id', user.id)
.eq('status', 'pending')
.in('status', ['pending', 'confirmed'])
.maybeSingle();
if (existingRequest) {
const errorMsg = existingRequest.status === 'confirmed'
? 'Your account is already scheduled for deletion. You can cancel it from your account settings.'
: 'You already have a pending deletion request. Check your email for the confirmation code.';
return new Response(
JSON.stringify({
error: 'You already have a pending deletion request',
error: errorMsg,
request: existingRequest,
}),
{
status: 400,
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
},
}
);
}
@@ -131,7 +139,9 @@ serve(async (req) => {
<h3>CONFIRMATION CODE: <strong>${confirmationCode}</strong></h3>
<p><strong>IMPORTANT:</strong> You have 24 hours to enter this code to confirm the deletion. After entering the code, your account will be deactivated and you'll have 14 days to cancel before permanent deletion.</p>
<p><strong>Need to cancel?</strong> You can cancel at any time during the 14-day period after confirming.</p>
<p><strong>Need to cancel?</strong> You can cancel at any time - before OR after confirming - during the 14-day period.</p>
<p><strong>Changed your mind?</strong> Simply log in to your account settings and click "Cancel Deletion".</p>
`,
};