mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 23:31:12 -05:00
Fix account deletion flow
This commit is contained in:
@@ -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>
|
||||
`,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user