feat(web): Login/Register страницы, protected routes, logout

- ProtectedRoute: loading -> спиннер, !user -> /login, иначе children
- LoginPage/RegisterPage: field+react-hook-form/zod, ошибка через role=alert,
  редирект на /domains при успехе/уже авторизован
- main.tsx: AuthProvider + QueryCache/MutationCache onError -> notifyUnauthorized
  на UnauthorizedError (сброс сессии из кода вне React-дерева)
- AuthContext: logout и notifyUnauthorized чистят react-query кэш (qc.clear())
- Layout: email пользователя + кнопка Выйти
- App: /login и /register публичные (авторизованный -> /domains), остальное
  под ProtectedRoute

Починка page-тестов (Accounts/Domains/Templates/DomainDiff/App): AuthProvider
+ мок api.auth.me, спай-ассерты обновлены под projectId-первым-аргументом
сигнатур api.* (T5).
This commit is contained in:
2026-07-03 21:21:29 +07:00
parent 222d6c0453
commit 5a4d560e70
15 changed files with 658 additions and 54 deletions
+21 -3
View File
@@ -1,6 +1,8 @@
import type { ReactNode } from "react"
import { NavLink, useLocation } from "react-router-dom"
import { Globe, Users, LayoutTemplate, SquareTerminal } from "lucide-react"
import { NavLink, useLocation, useNavigate } from "react-router-dom"
import { Globe, LogOut, Users, LayoutTemplate, SquareTerminal } from "lucide-react"
import { useAuth } from "@/auth/AuthContext"
import { Button } from "@/components/ui/button"
import { cn } from "@/lib/utils"
const NAV = [
@@ -11,6 +13,13 @@ const NAV = [
export function Layout({ children }: { children: ReactNode }) {
const location = useLocation()
const navigate = useNavigate()
const { user, logout } = useAuth()
async function onLogout() {
await logout()
navigate("/login", { replace: true })
}
return (
<div className="flex h-screen w-full overflow-hidden bg-background text-foreground">
@@ -64,10 +73,19 @@ export function Layout({ children }: { children: ReactNode }) {
</aside>
<div className="flex flex-1 flex-col overflow-hidden">
<header className="flex h-11 shrink-0 items-center border-b border-border px-6">
<header className="flex h-11 shrink-0 items-center justify-between border-b border-border px-6">
<span className="font-dns text-xs text-muted-foreground">
{location.pathname}
</span>
{user && (
<div className="flex items-center gap-3">
<span className="font-dns text-xs text-muted-foreground">{user.email}</span>
<Button variant="ghost" size="sm" onClick={onLogout}>
<LogOut className="size-3.5" strokeWidth={1.75} />
Выйти
</Button>
</div>
)}
</header>
<main className="flex-1 overflow-auto">{children}</main>
</div>