diff --git a/admin-next/src/app/login/page.tsx b/admin-next/src/app/login/page.tsx index a97a785..2b1b29f 100755 --- a/admin-next/src/app/login/page.tsx +++ b/admin-next/src/app/login/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; @@ -18,7 +18,16 @@ import { toast } from "sonner"; export function LoginPage() { const [token, setToken] = useState(""); const [loading, setLoading] = useState(false); - const { login } = useAuthStore(); + const { login, checkSession } = useAuthStore(); + + // Если сессия уже активна — сразу в админку (не показывать форму) + useEffect(() => { + checkSession().then((ok) => { + if (ok) { + window.location.href = "/"; + } + }); + }, [checkSession]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -43,7 +52,8 @@ export function LoginPage() { const { role } = await sessionRes.json(); login(role); toast.success("Logged in successfully"); - window.location.hash = "/"; + // Полный редирект в корень админки (AppPage сам решает, показывать ли Dashboard) + window.location.href = "/"; } else { toast.error("Session verification failed. Please try again."); }