fix(admin): login redirect — full location.href=/ instead of hash, session check on mount

- window.location.href='/' after login (was window.location.hash='/' which stayed on /login#/)
- checkSession on mount: already-authenticated users skip login form
This commit is contained in:
NW
2026-08-08 13:12:52 +01:00
parent 9aa3e41c3f
commit c7a4463ac4

View File

@@ -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.");
}