mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:51:13 -05:00
Fix composite submission protections
Implement Phase 4 by adding `recordSubmissionAttempt` and `withRetry` logic to the ban check for composite submissions. This ensures better error handling and prevents bypass of ban checks due to transient network issues.
This commit is contained in:
@@ -252,9 +252,12 @@ async function submitCompositeCreation(
|
|||||||
dependencies: CompositeSubmissionDependency[],
|
dependencies: CompositeSubmissionDependency[],
|
||||||
userId: string
|
userId: string
|
||||||
): Promise<{ submitted: boolean; submissionId: string }> {
|
): Promise<{ submitted: boolean; submissionId: string }> {
|
||||||
|
const { withRetry } = await import('./retryHelpers');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Phase 3: Rate limiting check
|
// Phase 3: Rate limiting check
|
||||||
checkRateLimitOrThrow(userId, 'composite_creation');
|
checkRateLimitOrThrow(userId, 'composite_creation');
|
||||||
|
recordSubmissionAttempt(userId);
|
||||||
|
|
||||||
breadcrumb.userAction('Start composite submission', 'submitCompositeCreation', {
|
breadcrumb.userAction('Start composite submission', 'submitCompositeCreation', {
|
||||||
primaryType: primaryEntity.type,
|
primaryType: primaryEntity.type,
|
||||||
@@ -262,24 +265,23 @@ async function submitCompositeCreation(
|
|||||||
userId
|
userId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if user is banned
|
// Check if user is banned with retry logic
|
||||||
breadcrumb.apiCall('profiles', 'SELECT');
|
breadcrumb.apiCall('profiles', 'SELECT');
|
||||||
try {
|
const profile = await withRetry(
|
||||||
const { data: profile, error } = await supabase
|
async () => {
|
||||||
.from('profiles')
|
const { data, error } = await supabase
|
||||||
.select('banned')
|
.from('profiles')
|
||||||
.eq('user_id', userId)
|
.select('banned')
|
||||||
.single();
|
.eq('user_id', userId)
|
||||||
|
.single();
|
||||||
|
if (error) throw error;
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
{ maxAttempts: 2 }
|
||||||
|
);
|
||||||
|
|
||||||
if (error) {
|
if (profile?.banned) {
|
||||||
throw new Error(`Failed to check user status: ${error.message}`);
|
throw new Error('Account suspended. Contact support for assistance.');
|
||||||
}
|
|
||||||
|
|
||||||
if (profile?.banned) {
|
|
||||||
throw new Error('Account suspended. Contact support for assistance.');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw error instanceof Error ? error : new Error(`User check failed: ${String(error)}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload all pending images for all entities
|
// Upload all pending images for all entities
|
||||||
@@ -526,7 +528,6 @@ async function submitCompositeCreation(
|
|||||||
|
|
||||||
// Use RPC to create submission with items atomically with retry logic
|
// Use RPC to create submission with items atomically with retry logic
|
||||||
breadcrumb.apiCall('create_submission_with_items', 'RPC');
|
breadcrumb.apiCall('create_submission_with_items', 'RPC');
|
||||||
const { withRetry } = await import('./retryHelpers');
|
|
||||||
const { toast } = await import('@/hooks/use-toast');
|
const { toast } = await import('@/hooks/use-toast');
|
||||||
|
|
||||||
const result = await withRetry(
|
const result = await withRetry(
|
||||||
|
|||||||
Reference in New Issue
Block a user