'use client' import { useState, useEffect } from 'react' import Link from 'next/link' export default function Dashboard() { const [token, setToken] = useState('') const [apiKey, setApiKey] = useState('') const [url, setUrl] = useState('https://example.com') const [endpoint, setEndpoint] = useState('screenshot') const [result, setResult] = useState('') const [loading, setLoading] = useState(false) const [apiKeys, setApiKeys] = useState<{id: string, name: string}[]>([]) const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [isLoggedIn, setIsLoggedIn] = useState(false) const [newKeyName, setNewKeyName] = useState('') const endpoints = ['crawl', 'content', 'screenshot', 'pdf', 'markdown', 'snapshot', 'scrape', 'json', 'links'] useEffect(() => { const saved = localStorage.getItem('crawlapi_token') if (saved) { setToken(saved) setIsLoggedIn(true) fetchApiKeys(saved) } }, []) async function login() { try { const res = await fetch('http://localhost:3000/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }) const data = await res.json() if (data.token) { setToken(data.token) setIsLoggedIn(true) localStorage.setItem('crawlapi_token', data.token) fetchApiKeys(data.token) } else { setResult(JSON.stringify(data, null, 2)) } } catch (e) { setResult(String(e)) } } async function fetchApiKeys(t: string) { try { const res = await fetch('http://localhost:3000/api/auth/api-keys', { headers: { 'x-auth-token': t }, }) const data = await res.json() setApiKeys(data || []) } catch (e) { console.error(e) } } async function createApiKey() { try { const res = await fetch('http://localhost:3000/api/auth/api-keys', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-auth-token': token, }, body: JSON.stringify({ name: newKeyName || 'New Key' }), }) const data = await res.json() setResult(JSON.stringify(data, null, 2)) fetchApiKeys(token) } catch (e) { setResult(String(e)) } } async function testApi() { setLoading(true) try { const res = await fetch(`http://localhost:3000/api/${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, body: JSON.stringify({ url }), }) const data = await res.json() setResult(JSON.stringify(data, null, 2)) } catch (e) { setResult(String(e)) } finally { setLoading(false) } } return (

Dashboard

Test your API keys and monitor usage.

{!isLoggedIn ? (

Login

or
setEmail(e.target.value)} placeholder="demo@crawlapi.dev" style={{ width: '100%', padding: 12, background: '#1a1a1a', border: '1px solid #333', borderRadius: 8, color: '#fff', fontSize: 14, boxSizing: 'border-box' }} /> setPassword(e.target.value)} placeholder="password" style={{ width: '100%', padding: 12, background: '#1a1a1a', border: '1px solid #333', borderRadius: 8, color: '#fff', fontSize: 14, boxSizing: 'border-box' }} />
) : ( <>

Your API Keys

setNewKeyName(e.target.value)} placeholder="Key name" style={{ flex: 1, padding: 12, background: '#1a1a1a', border: '1px solid #333', borderRadius: 8, color: '#fff', fontSize: 14, }} />
{apiKeys.length > 0 ? ( ) : (

No API keys yet. Create one above.

)}

Test API

setApiKey(e.target.value)} placeholder="your-api-key" style={{ width: '100%', padding: 12, background: '#1a1a1a', border: '1px solid #333', borderRadius: 8, color: '#fff', fontSize: 14, boxSizing: 'border-box' }} />
setUrl(e.target.value)} style={{ width: '100%', padding: 12, background: '#1a1a1a', border: '1px solid #333', borderRadius: 8, color: '#fff', fontSize: 14, boxSizing: 'border-box' }} />
)} {result && (

Response

{result}
)}
) }