"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription } from "@/components/ui/alert" import { TestTube, CheckCircle, XCircle } from "lucide-react" import apiClient from "@/lib/api-client" import { API_CONFIG } from "@/lib/config" export function ApiTest() { const [testResult, setTestResult] = useState("") const [loading, setLoading] = useState(false) const [error, setError] = useState("") const testApiConnection = async () => { setLoading(true) setError("") setTestResult("") try { console.log("๐Ÿงช Testing API connection...") // Test the login endpoint (this will fail but we can see the request) const response = await apiClient.post('/api/v1/auth/login', { email: "test@example.com", password: "test123" }) setTestResult("โœ… API connection successful!") console.log("โœ… Test response:", response.data) } catch (error: any) { console.log("โŒ Test error:", error) if (error.response) { // Server responded with error status - this is expected for invalid credentials setTestResult(`โœ… API connection working! Server responded with status: ${error.response.status}`) setError(`Expected error: ${error.response.data?.message || 'Invalid credentials'}`) } else if (error.request) { // Request was made but no response received setTestResult("โŒ API connection failed") setError("No response from server. Check if backend is running.") } else { // Something else happened setTestResult("โŒ API connection failed") setError(error.message || "Unknown error occurred") } } finally { setLoading(false) } } return ( API Connection Test Test the connection to your backend API
Backend URL: {API_CONFIG.BASE_URL}
Login Endpoint: {API_CONFIG.ENDPOINTS.LOGIN}
Full URL: {API_CONFIG.BASE_URL}{API_CONFIG.ENDPOINTS.LOGIN}
Auth Header: {API_CONFIG.AUTH_HEADER ? "โœ… Set" : "โŒ Not Set"}
{testResult && ( {testResult.includes("โœ…") ? ( ) : ( )} {testResult} )} {error && ( {error} )}
) }