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:
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user