import { FormEvent, useState } from 'react' import { Navigate, useSearchParams } from 'react-router-dom' import { ArrowRight, LockKeyhole, Phone } from 'lucide-react' import { Brand } from '../components/Brand' import { Footer } from '../components/Footer' import { useAuth } from '../AuthContext' export function AuthPage() { const [searchParams] = useSearchParams() const { user, authenticate } = useAuth() const [mode, setMode] = useState<'login' | 'register'>(() => searchParams.get('mode') === 'register' ? 'register' : 'login') const [busy, setBusy] = useState(false) const [error, setError] = useState('') if (user) { return } async function submit(e: FormEvent) { e.preventDefault() const f = new FormData(e.currentTarget) const password = String(f.get('password')) if (mode === 'register' && password !== String(f.get('confirmPassword'))) { setError('两次输入的密码不一致') return } setBusy(true) setError('') try { await authenticate(mode, String(f.get('phone')), password) } catch (x) { setError(x instanceof Error ? x.message : '操作失败') } finally { setBusy(false) } } return ( 智能课程工坊 让每一门好课, 留下清晰的星痕。 归集课程资产与讲师信息,让课程制作更简单。 {mode === 'login' ? '登录星痕' : '创建账号'} {mode === 'login' ? '使用手机号和密码继续' : '注册后即可开始'} 手机号 密码 {mode === 'register' && ( 确认密码 )} {error && {error}} {busy ? '请稍候…' : mode === 'login' ? '登录' : '注册'} { setMode(mode === 'login' ? 'register' : 'login') setError('') }} > {mode === 'login' ? '还没有账号?立即注册' : '已有账号?返回登录'} ) }
智能课程工坊
归集课程资产与讲师信息,让课程制作更简单。
{mode === 'login' ? '使用手机号和密码继续' : '注册后即可开始'}