// app/test/page.tsx 'use client'; import { useEffect, useState } from 'react'; export default function TestPage() { const [user, setUser] = useState(null); const [loginStatus, setLoginStatus] = useState(''); useEffect(() => { // Test GET request fetch('https://api.example.com/user') .then(res => res.json()) .then(data => setUser(data)); }, []); const handleLogin = async () => { // Test POST request const response = await fetch('https://api.example.com/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username: 'admin', password: 'password123' }) }); const result = await response.json(); setLoginStatus(response.ok ? 'Login successful' : `Error: ${result.error}`); }; return (
{JSON.stringify(user, null, 2)}
{loginStatus}