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

@@ -48,7 +48,7 @@ export function AccountDeletionDialog({ open, onOpenChange, userEmail, onDeletio
{ action: 'Request account deletion' }
);
sessionStorage.setItem('mfa_step_up_required', 'true');
sessionStorage.setItem('mfa_intended_path', '/settings?tab=privacy');
sessionStorage.setItem('mfa_intended_path', '/settings');
window.location.href = '/auth';
return;
}
@@ -66,6 +66,10 @@ export function AccountDeletionDialog({ open, onOpenChange, userEmail, onDeletio
if (error) throw error;
// Clear MFA session storage
sessionStorage.removeItem('mfa_step_up_required');
sessionStorage.removeItem('mfa_intended_path');
dispatch({
type: 'REQUEST_DELETION',
payload: { scheduledDate: data.scheduled_deletion_at }

View File

@@ -84,7 +84,7 @@ export function AccountProfileTab() {
isValid: usernameValidation.isAvailable !== false
});
// Check for existing deletion request on mount
// Check for existing deletion request on mount (both pending and confirmed)
useEffect(() => {
const checkDeletionRequest = async () => {
if (!user?.id) return;
@@ -93,7 +93,7 @@ export function AccountProfileTab() {
.from('account_deletion_requests')
.select('*')
.eq('user_id', user.id)
.eq('status', 'pending')
.in('status', ['pending', 'confirmed'])
.maybeSingle();
if (!error && data) {
@@ -210,12 +210,12 @@ export function AccountProfileTab() {
};
const handleDeletionRequested = async () => {
// Refresh deletion request data
// Refresh deletion request data (check for both pending and confirmed)
const { data, error } = await supabase
.from('account_deletion_requests')
.select('*')
.eq('user_id', user!.id)
.eq('status', 'pending')
.in('status', ['pending', 'confirmed'])
.maybeSingle();
if (!error && data) {
@@ -235,6 +235,7 @@ export function AccountProfileTab() {
{deletionRequest && (
<DeletionStatusBanner
scheduledDate={deletionRequest.scheduled_deletion_at}
status={deletionRequest.status as 'pending' | 'confirmed'}
onCancelled={handleDeletionCancelled}
/>
)}

View File

@@ -9,10 +9,11 @@ import { getErrorMessage } from '@/lib/errorHandler';
interface DeletionStatusBannerProps {
scheduledDate: string;
status: 'pending' | 'confirmed';
onCancelled: () => void;
}
export function DeletionStatusBanner({ scheduledDate, onCancelled }: DeletionStatusBannerProps) {
export function DeletionStatusBanner({ scheduledDate, status, onCancelled }: DeletionStatusBannerProps) {
const [loading, setLoading] = useState(false);
const { toast } = useToast();
@@ -64,20 +65,38 @@ export function DeletionStatusBanner({ scheduledDate, onCancelled }: DeletionSta
return (
<Alert variant="destructive" className="mb-6">
<AlertTriangle className="w-4 h-4" />
<AlertTitle>Account Deactivated - Deletion Scheduled</AlertTitle>
<AlertTitle>
{status === 'pending' ? 'Deletion Requested' : 'Account Deactivated - Deletion Scheduled'}
</AlertTitle>
<AlertDescription className="space-y-2">
<p>
Your account is <strong>deactivated</strong> and scheduled for permanent deletion on <strong>{formattedDate}</strong>.
</p>
<p className="text-sm">
{daysRemaining > 0 ? (
<>
<strong>{daysRemaining}</strong> day{daysRemaining !== 1 ? 's' : ''} remaining to cancel.
</>
) : (
'You can now confirm deletion with your confirmation code.'
)}
</p>
{status === 'pending' ? (
<>
<p>
You have requested account deletion. Please check your email for a confirmation code.
You must enter the code within 24 hours to proceed.
</p>
<p className="text-sm text-muted-foreground">
After confirming with the code, your account will be deactivated and scheduled for deletion on{' '}
<strong>{formattedDate}</strong>.
</p>
</>
) : (
<>
<p>
Your account is <strong>deactivated</strong> and scheduled for permanent deletion on{' '}
<strong>{formattedDate}</strong>.
</p>
<p className="text-sm">
{daysRemaining > 0 ? (
<>
<strong>{daysRemaining}</strong> day{daysRemaining !== 1 ? 's' : ''} remaining to cancel.
</>
) : (
'Your account will be deleted within 24 hours.'
)}
</p>
</>
)}
<div className="flex gap-2 mt-3">
<Button
variant="outline"