feat(frontend): implement center auth session flow with route guard
This commit is contained in:
@@ -1,8 +1,41 @@
|
||||
import { useState } from 'react'
|
||||
import type { FormEvent } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useAuth } from '../auth/auth-context'
|
||||
|
||||
export default function LoginPage() {
|
||||
const navigate = useNavigate()
|
||||
const { login, isAuthed, session } = useAuth()
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
|
||||
async function onSubmit(e: FormEvent) {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
try {
|
||||
await login(email, password)
|
||||
navigate('/workspace')
|
||||
} catch {
|
||||
setError('登录失败,请检查账号密码')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section>
|
||||
<h2>登录</h2>
|
||||
<p>下一步接入 Center 登录与 token 管理。</p>
|
||||
{isAuthed ? <p>当前用户:{session?.user.email}</p> : null}
|
||||
<form onSubmit={onSubmit} style={{ display: 'grid', gap: 8, maxWidth: 420 }}>
|
||||
<input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" type="email" />
|
||||
<input
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Password"
|
||||
type="password"
|
||||
/>
|
||||
<button type="submit">登录</button>
|
||||
</form>
|
||||
<p>{error}</p>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@ export default function WorkspacePage() {
|
||||
<section>
|
||||
<h2>工作台</h2>
|
||||
<form onSubmit={onSave} style={{ display: 'grid', gap: 8, maxWidth: 760 }}>
|
||||
<input
|
||||
value={form.centerApiBase}
|
||||
onChange={(e) => setForm((v) => ({ ...v, centerApiBase: e.target.value }))}
|
||||
placeholder="Center API Base"
|
||||
/>
|
||||
<input
|
||||
value={form.guildApiBase}
|
||||
onChange={(e) => setForm((v) => ({ ...v, guildApiBase: e.target.value }))}
|
||||
|
||||
Reference in New Issue
Block a user