mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 08:11:13 -05:00
Refactor: Add MFA check and improve error handling
This commit is contained in:
@@ -263,6 +263,22 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
|
|
||||||
setActionLoading(item.id);
|
setActionLoading(item.id);
|
||||||
|
|
||||||
|
// Check MFA (AAL2) requirement before moderation action
|
||||||
|
const { data: { session } } = await supabase.auth.getSession();
|
||||||
|
|
||||||
|
// Access AAL from session metadata
|
||||||
|
const aal = session?.user?.app_metadata?.aal || session?.user?.user_metadata?.aal;
|
||||||
|
|
||||||
|
if (aal !== 'aal2') {
|
||||||
|
toast({
|
||||||
|
title: "MFA Verification Required",
|
||||||
|
description: "You must complete multi-factor authentication to perform moderation actions.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
setActionLoading(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Optimistic update
|
// Optimistic update
|
||||||
const shouldRemove =
|
const shouldRemove =
|
||||||
(filters.statusFilter === "pending" || filters.statusFilter === "flagged") &&
|
(filters.statusFilter === "pending" || filters.statusFilter === "flagged") &&
|
||||||
@@ -389,7 +405,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
await queueQuery.refetch();
|
await queueQuery.refetch();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMsg = getErrorMessage(error);
|
const errorMsg = getErrorMessage(error);
|
||||||
console.error("Error moderating content:", errorMsg);
|
console.error("Error moderating content:", errorMsg, error);
|
||||||
|
|
||||||
// Revert optimistic update
|
// Revert optimistic update
|
||||||
setItems((prev) => {
|
setItems((prev) => {
|
||||||
@@ -401,11 +417,23 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
toast({
|
// Check for RLS/permission errors
|
||||||
title: "Error",
|
if (errorMsg.includes('row-level security') ||
|
||||||
description: errorMsg || `Failed to ${action} content`,
|
errorMsg.includes('permission denied') ||
|
||||||
variant: "destructive",
|
errorMsg.includes('policy') ||
|
||||||
});
|
errorMsg.includes('violates row-level security')) {
|
||||||
|
toast({
|
||||||
|
title: "Permission Denied",
|
||||||
|
description: "You don't have permission to perform this action. MFA verification may be required.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: errorMsg || `Failed to ${action} content`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setActionLoading(null);
|
setActionLoading(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user