'use client' import { useState } from 'react' import { useAuthStore } from '@/lib/auth' export function AuthButton() { const { isAuthenticated, username, loading, login, register, logout } = useAuthStore() const [showRegister, setShowRegister] = useState(false) const [registerName, setRegisterName] = useState('') const handleLogin = async () => { try { await login() } catch (e: unknown) { if (e instanceof Error && e.name === 'NotAllowedError') { setShowRegister(true) } } } const handleRegister = async () => { if (!registerName.trim()) return try { await register(registerName.trim()) setShowRegister(false) setRegisterName('') } catch (e: unknown) { alert('Registration failed: ' + (e instanceof Error ? e.message : 'Unknown error')) } } if (loading) { return Authenticating... } if (isAuthenticated) { return (