feat(frontend): implement center auth session flow with route guard
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { Link, Outlet } from 'react-router-dom'
|
||||
import { useAuth } from '../auth/auth-context'
|
||||
|
||||
export default function AppLayout() {
|
||||
const { isAuthed, session, logout } = useAuth()
|
||||
|
||||
return (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '220px 1fr', minHeight: '100vh' }}>
|
||||
<aside style={{ borderRight: '1px solid #ddd', padding: 16 }}>
|
||||
@@ -10,6 +13,18 @@ export default function AppLayout() {
|
||||
<Link to="/chat">聊天</Link>
|
||||
<Link to="/login">登录</Link>
|
||||
</nav>
|
||||
<div style={{ marginTop: 16, fontSize: 12 }}>
|
||||
{isAuthed ? (
|
||||
<>
|
||||
<div>{session?.user.email}</div>
|
||||
<button onClick={() => logout()} style={{ marginTop: 6 }}>
|
||||
登出
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<span>未登录</span>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
<main style={{ padding: 16 }}>
|
||||
<Outlet />
|
||||
|
||||
Reference in New Issue
Block a user