import React, { useState } from 'react' import { Button } from './Button' interface LoginProps { onLogin: (token: string) => void } export const Login: React.FC = ({ onLogin }) => { const [token, setToken] = useState('') const [name, setName] = useState('') const [description, setDescription] = useState('') const [isCreating, setIsCreating] = useState(false) const [error, setError] = useState('') const [createdToken, setCreatedToken] = useState('') const handleLoginWithToken = () => { if (!token.trim()) { setError('Please enter a token') return } localStorage.setItem('admin_token', token.trim()) onLogin(token.trim()) } const handleCreateToken = async () => { if (!name.trim()) { setError('Please enter a token name') return } setIsCreating(true) setError('') try { const response = await fetch('http://localhost:8000/api/v1/admin/auth/token', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ name: name.trim(), description: description.trim() || undefined, }), }) if (!response.ok) { throw new Error('Failed to create token') } const data = await response.json() setCreatedToken(data.token) setToken(data.token) setError('') } catch (err) { setError('Failed to create token. Please check your connection.') console.error(err) } finally { setIsCreating(false) } } const handleUseCreatedToken = () => { if (createdToken) { localStorage.setItem('admin_token', createdToken) onLogin(createdToken) } } return (

Admin Authentication

Sign in with an admin token to access the document management system

{error && (
{error}
)} {createdToken && (

Token created successfully!

{createdToken}

Save this token securely. You won't be able to see it again.

)}
{/* Login with existing token */}

Sign in with existing token

setToken(e.target.value)} placeholder="Enter your admin token" className="w-full px-3 py-2 border border-warm-border rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-warm-state-info font-mono" onKeyDown={(e) => e.key === 'Enter' && handleLoginWithToken()} />
OR
{/* Create new token */}

Create new admin token

setName(e.target.value)} placeholder="e.g., my-laptop" className="w-full px-3 py-2 border border-warm-border rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-warm-state-info" />
setDescription(e.target.value)} placeholder="e.g., Personal laptop access" className="w-full px-3 py-2 border border-warm-border rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-warm-state-info" />

Admin tokens are used to authenticate with the document management API. Keep your tokens secure and never share them.

) }