feat: Implement authentication integration

This commit is contained in:
gpt-engineer-app[bot]
2025-09-30 13:51:59 +00:00
parent 083a4af08c
commit f7ce456cc0
3 changed files with 30 additions and 4 deletions

View File

@@ -445,7 +445,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
} }
// STEP 4: Update submission status // STEP 4: Update submission status
const { data: { user } } = await supabase.auth.getUser();
const { error: updateError } = await supabase const { error: updateError } = await supabase
.from('content_submissions') .from('content_submissions')
.update({ .update({
@@ -482,7 +481,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
}; };
// Get current user ID for reviewer tracking // Get current user ID for reviewer tracking
const { data: { user } } = await supabase.auth.getUser();
if (user) { if (user) {
updateData[reviewerField] = user.id; updateData[reviewerField] = user.id;
} }

View File

@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { useToast } from '@/hooks/use-toast'; import { useToast } from '@/hooks/use-toast';
import { useUserRole } from '@/hooks/useUserRole'; import { useUserRole } from '@/hooks/useUserRole';
import { useAuth } from '@/hooks/useAuth';
import { import {
fetchSubmissionItems, fetchSubmissionItems,
buildDependencyTree, buildDependencyTree,
@@ -48,6 +49,7 @@ export function SubmissionReviewManager({
const { toast } = useToast(); const { toast } = useToast();
const { isAdmin, isSuperuser } = useUserRole(); const { isAdmin, isSuperuser } = useUserRole();
const { user } = useAuth();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const Container = isMobile ? Sheet : Dialog; const Container = isMobile ? Sheet : Dialog;
@@ -116,10 +118,19 @@ export function SubmissionReviewManager({
}; };
const handleApprove = async () => { const handleApprove = async () => {
if (!user?.id) {
toast({
title: 'Authentication Required',
description: 'You must be logged in to approve items',
variant: 'destructive',
});
return;
}
setLoading(true); setLoading(true);
try { try {
const selectedItems = items.filter(item => selectedItemIds.has(item.id)); const selectedItems = items.filter(item => selectedItemIds.has(item.id));
await approveSubmissionItems(selectedItems, 'current-user-id'); // TODO: Get from auth await approveSubmissionItems(selectedItems, user.id);
toast({ toast({
title: 'Success', title: 'Success',
@@ -162,9 +173,18 @@ export function SubmissionReviewManager({
}; };
const handleEscalate = async (reason: string) => { const handleEscalate = async (reason: string) => {
if (!user?.id) {
toast({
title: 'Authentication Required',
description: 'You must be logged in to escalate submissions',
variant: 'destructive',
});
return;
}
setLoading(true); setLoading(true);
try { try {
await escalateSubmission(submissionId, reason, 'current-user-id'); // TODO: Get from auth await escalateSubmission(submissionId, reason, user.id);
toast({ toast({
title: 'Escalated', title: 'Escalated',

View File

@@ -154,6 +154,10 @@ export async function approveSubmissionItems(
items: SubmissionItemWithDeps[], items: SubmissionItemWithDeps[],
userId: string userId: string
): Promise<void> { ): Promise<void> {
if (!userId) {
throw new Error('User authentication required to approve items');
}
// Sort by dependency order (parents first) // Sort by dependency order (parents first)
const sortedItems = topologicalSort(items); const sortedItems = topologicalSort(items);
@@ -285,6 +289,10 @@ export async function escalateSubmission(
reason: string, reason: string,
userId: string userId: string
): Promise<void> { ): Promise<void> {
if (!userId) {
throw new Error('User authentication required to escalate submission');
}
const { error } = await supabase const { error } = await supabase
.from('content_submissions') .from('content_submissions')
.update({ .update({