fix: Use fetchWithAuth for fetching test data in CBT exam view

This commit is contained in:
2026-09-24 20:08:09 +05:30
parent a294ee8b9e
commit a8d81e3482

View File

@@ -17,6 +17,7 @@ import { Calculator } from "@/components/CBT/Calculator"
import { Scratchpad } from "@/components/CBT/Scratchpad"
import { PeriodicTable } from "@/components/CBT/PeriodicTable"
import { ExamResult } from "@/components/CBT/ExamResult"
import { fetchWithAuth } from "@/lib/apiClient"
// Dummy data for testing the CBT client engine
const DUMMY_QUESTIONS = Array.from({ length: 20 }).map((_, i) => ({
@@ -98,8 +99,7 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
useEffect(() => {
async function fetchExamData() {
try {
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000';
const testRes = await fetch(`${apiUrl}/api/tests/${examId}?user_id=${userId}`);
const testRes = await fetchWithAuth(`/api/tests/${examId}?user_id=${userId}`);
if (!testRes.ok) throw new Error("Failed to fetch test structure");
const testData = await testRes.json();
@@ -125,7 +125,7 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
questionIds.push(...section.questions);
});
const qRes = await fetch(`${apiUrl}/api/tests/${examId}/questions`);
const qRes = await fetchWithAuth(`/api/tests/${examId}/questions`);
if (!qRes.ok) throw new Error("Failed to fetch questions in bulk");
const allQuestionsData = await qRes.json();