Files
probably-rendering-one-more…/apps/waterfall-wiki/src/pages/login.tsx
T
codex-bot 00e1b70398
waterfall-wiki CI and deployment / verify-and-deploy (push) Successful in 17m31s
Restyle login with the Prompt logo and warm brand colors
2026-10-27 14:34:59 +08:00

18 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Head from 'next/head';
import { useRouter } from 'next/router';
import { useState, type FormEvent } from 'react';
// Keep this page independent of server-only authentication modules.
export default function Login() {
const router = useRouter(); const [code,setCode] = useState(''); const [error,setError] = useState(''); const [busy,setBusy] = useState(false);
async function submit(event: FormEvent) {
event.preventDefault(); if (busy) return; setBusy(true); setError('');
try {
const response = await fetch('/api/auth/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({code})});
const data = await response.json(); if (!response.ok) { setError(data.error || '登录没有完成'); setCode(''); return; }
const next = router.query.next;
window.location.assign(typeof next === 'string' && next.startsWith('/') && !next.startsWith('//') && !/[\\\r\n]/.test(next) && !next.startsWith('/login') ? next : '/');
} catch { setError('暂时无法连接,请稍后重试'); } finally { setBusy(false); }
}
return <><Head><title>动态码登录 · PROMPT</title><meta name="robots" content="noindex,nofollow"/></Head><main className="auth-page"><form className="auth-card" onSubmit={submit}><img className="auth-logo" src="/brand-mark.svg" width={64} height={64} alt="Prompt"/><h1>输入动态码</h1><p className="auth-description">打开验证器,输入当前的 6 位动态码。</p><label htmlFor="auth-code">动态码</label><input id="auth-code" autoFocus inputMode="numeric" autoComplete="one-time-code" pattern="[0-9]{6}" maxLength={6} required value={code} onChange={e=>setCode(e.target.value.replace(/\D/g,''))} placeholder="000000" aria-describedby="auth-error"/><div id="auth-error" role="alert" className="auth-error">{error}</div><button type="submit" disabled={busy || code.length !== 6}>{busy ? '正在验证…' : '进入知识库'}</button><p className="auth-footnote">尚未绑定验证器?请联系管理员。</p></form></main></>;
}