From c7a4463ac49c608fbb7c99b657442d02b6537e8f Mon Sep 17 00:00:00 2001 From: NW Date: Sat, 8 Aug 2026 13:12:52 +0100 Subject: [PATCH] =?UTF-8?q?fix(admin):=20login=20redirect=20=E2=80=94=20fu?= =?UTF-8?q?ll=20location.href=3D/=20instead=20of=20hash,=20session=20check?= =?UTF-8?q?=20on=20mount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - window.location.href='/' after login (was window.location.hash='/' which stayed on /login#/) - checkSession on mount: already-authenticated users skip login form --- admin-next/src/app/login/page.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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."); }