import { createFileRoute, redirect, useRouter } from '@tanstack/react-router' import { useState } from 'react' import { authClient } from '@/server/auth/client' import { checkInitialized, completeSetup } from '@/server/auth/functions' export const Route = createFileRoute('/setup' as never)({ beforeLoad: async () => { const initialized = await checkInitialized() if (initialized) { throw redirect({ to: '/login' as never }) } }, component: SetupPage, }) function SetupPage() { const router = useRouter() const [name, setName] = useState('') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [recoveryKey, setRecoveryKey] = useState(null) const [copied, setCopied] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (password !== confirmPassword) { setError('两次输入的密码不一致') return } if (password.length < 8) { setError('密码至少需要 8 个字符') return } setLoading(true) const { error: signUpError } = await authClient.signUp.email({ name, email, password, }) if (signUpError) { setError(signUpError.message ?? '创建账号失败,请重试') setLoading(false) return } const result = await completeSetup() setRecoveryKey(result.recoveryKey) setLoading(false) } const handleCopy = async () => { if (!recoveryKey) return await navigator.clipboard.writeText(recoveryKey) setCopied(true) setTimeout(() => setCopied(false), 2000) } const handleContinue = () => { router.navigate({ to: '/' as never }) } if (recoveryKey) { return (

Kairos

初始化完成

请妥善保存你的恢复密钥(仅显示一次)

如果无法登录且无法访问服务器终端,可通过此密钥重置账户。

{recoveryKey}
) } return (

Kairos

初始化你的人生操作系统

setName(e.target.value)} className="w-full px-4 py-3 rounded-xl bg-slate-50 border-0 ring-1 ring-slate-200 focus:ring-2 focus:ring-indigo-500 outline-none transition-all text-slate-700 placeholder:text-slate-400" placeholder="你的名字" disabled={loading} />
setEmail(e.target.value)} className="w-full px-4 py-3 rounded-xl bg-slate-50 border-0 ring-1 ring-slate-200 focus:ring-2 focus:ring-indigo-500 outline-none transition-all text-slate-700 placeholder:text-slate-400" placeholder="your@email.com" disabled={loading} />
setPassword(e.target.value)} className="w-full px-4 py-3 rounded-xl bg-slate-50 border-0 ring-1 ring-slate-200 focus:ring-2 focus:ring-indigo-500 outline-none transition-all text-slate-700 placeholder:text-slate-400" placeholder="至少 8 个字符" disabled={loading} />
setConfirmPassword(e.target.value)} className="w-full px-4 py-3 rounded-xl bg-slate-50 border-0 ring-1 ring-slate-200 focus:ring-2 focus:ring-indigo-500 outline-none transition-all text-slate-700 placeholder:text-slate-400" placeholder="再次输入密码" disabled={loading} />
{error &&

{error}

}
) }