refactor API URL handling in TestList and AuthContext components

This commit is contained in:
ishikabhoyar
2025-10-31 15:12:58 +05:30
parent b18dc5f21b
commit abc15efabd
2 changed files with 8 additions and 4 deletions

View File

@@ -21,7 +21,8 @@ const TestList = () => {
const fetchTests = async () => { const fetchTests = async () => {
try { try {
console.log('Fetching tests with token:', token?.substring(0, 50) + '...'); console.log('Fetching tests with token:', token?.substring(0, 50) + '...');
const response = await fetch('http://localhost:5000/api/students/tests', { const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api';
const response = await fetch(`${API_URL}/students/tests`, {
headers: { headers: {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} }
@@ -57,7 +58,8 @@ const TestList = () => {
const handleStartTest = async (test) => { const handleStartTest = async (test) => {
try { try {
const response = await fetch(`http://localhost:5000/api/students/tests/${test.id}/questions`, { const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api';
const response = await fetch(`${API_URL}/students/tests/${test.id}/questions`, {
headers: { headers: {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} }
@@ -83,7 +85,8 @@ const TestList = () => {
if (!selectedTest || !password) return; if (!selectedTest || !password) return;
try { try {
const response = await fetch(`http://localhost:5000/api/students/tests/${selectedTest.id}/verify-password`, { const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api';
const response = await fetch(`${API_URL}/students/tests/${selectedTest.id}/verify-password`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${token}`,

View File

@@ -41,7 +41,8 @@ export const AuthProvider = ({ children }) => {
// For Google OAuth login // For Google OAuth login
if (googleToken && userInfo) { if (googleToken && userInfo) {
// Exchange Google token for our JWT // Exchange Google token for our JWT
const response = await fetch('http://localhost:5000/api/students/login', { const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api';
const response = await fetch(`${API_URL}/students/login`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',