Files
sfera/src/components/auth-guard.tsx
Veronika Smirnova 6b425d075f Унификация UI раздела Партнеры и создание системы документирования
🎨 Унификация UI:
- Полная унификация визуала вкладок Рефералы и Мои контрагенты
- Исправлены React Hooks ошибки в sidebar.tsx
- Убрана лишняя обертка glass-card в partners-dashboard.tsx
- Исправлена цветовая схема (purple → yellow)
- Табличный формат вместо карточного grid-layout
- Компактные блоки статистики (4 метрики в ряд)
- Правильная прозрачность glass-morphism эффектов

📚 Документация:
- Переименован referral-system-rules.md → partners-rules.md
- Детальные UI/UX правила в partners-rules.md
- Правила унификации в visual-design-rules.md
- Обновлен current-session.md
- Создан development-diary.md

🚀 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 15:38:23 +03:00

54 lines
1.8 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.

'use client'
import { useEffect, useState, useRef } from 'react'
import { useAuth } from '@/hooks/useAuth'
import { AuthFlow } from './auth/auth-flow'
interface AuthGuardProps {
children: React.ReactNode
fallback?: React.ReactNode
}
export function AuthGuard({ children, fallback }: AuthGuardProps) {
const { isAuthenticated, isLoading, checkAuth, user } = useAuth()
const [isChecking, setIsChecking] = useState(true)
const initRef = useRef(false) // Защита от повторных инициализаций
useEffect(() => {
const initAuth = async () => {
if (initRef.current) {
return
}
initRef.current = true
await checkAuth()
setIsChecking(false)
}
initAuth()
}, [checkAuth, isAuthenticated, user]) // Добавляем зависимости как требует линтер
// Показываем лоадер пока проверяем авторизацию
if (isChecking || isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center text-white">
<div className="animate-spin rounded-full h-16 w-16 border-4 border-white border-t-transparent mx-auto mb-4"></div>
<p className="text-white/80">Проверяем авторизацию...</p>
</div>
</div>
)
}
// Если не авторизован ИЛИ нет организации (незавершенная регистрация), показываем форму авторизации
if (!isAuthenticated || (isAuthenticated && user && !user.organization)) {
return fallback || <AuthFlow />
}
// Если авторизован И у пользователя есть организация, показываем защищенный контент
return <>{children}</>
}