'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { authClient } from '@/lib/auth-client'; import Link from 'next/link'; type Tab = 'password' | 'ldap'; export default function SignInPage() { const router = useRouter(); const [tab, setTab] = useState('password'); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [credential, setCredential] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const ldapEnabled = process.env.NEXT_PUBLIC_LDAP_ENABLED === 'true'; const handleEmailSignIn = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { const { error } = await authClient.signIn.email({ email, password }); if (error) throw new Error(error.message); router.push('/dashboard'); router.refresh(); } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Ошибка входа'); } finally { setLoading(false); } }; const handleLdapSignIn = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { const res = await fetch('/api/auth/sign-in/ldap', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ credential, password, callbackURL: '/dashboard' }), credentials: 'include', }); const data = await res.json(); if (!res.ok || data?.error) throw new Error(data?.message || data?.error?.message || 'Ошибка входа'); router.push('/dashboard'); router.refresh(); } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Ошибка LDAP входа'); } finally { setLoading(false); } }; return (

Вход в систему

{ldapEnabled && (
)} {error && (
{error}
)} {tab === 'password' ? (
setEmail(e.target.value)} required style={{ width: '100%', padding: 12, marginBottom: 12, border: '1px solid #ddd', borderRadius: 8, boxSizing: 'border-box', }} /> setPassword(e.target.value)} required style={{ width: '100%', padding: 12, marginBottom: 16, border: '1px solid #ddd', borderRadius: 8, boxSizing: 'border-box', }} />
) : (
setCredential(e.target.value)} required style={{ width: '100%', padding: 12, marginBottom: 12, border: '1px solid #ddd', borderRadius: 8, boxSizing: 'border-box', }} /> setPassword(e.target.value)} required style={{ width: '100%', padding: 12, marginBottom: 16, border: '1px solid #ddd', borderRadius: 8, boxSizing: 'border-box', }} />
)}

Нет аккаунта?{' '} Регистрация

); }