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";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
@@ -18,7 +18,16 @@ import { toast } from "sonner";
|
|||||||
export function LoginPage() {
|
export function LoginPage() {
|
||||||
const [token, setToken] = useState("");
|
const [token, setToken] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
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) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -43,7 +52,8 @@ export function LoginPage() {
|
|||||||
const { role } = await sessionRes.json();
|
const { role } = await sessionRes.json();
|
||||||
login(role);
|
login(role);
|
||||||
toast.success("Logged in successfully");
|
toast.success("Logged in successfully");
|
||||||
window.location.hash = "/";
|
// Полный редирект в корень админки (AppPage сам решает, показывать ли Dashboard)
|
||||||
|
window.location.href = "/";
|
||||||
} else {
|
} else {
|
||||||
toast.error("Session verification failed. Please try again.");
|
toast.error("Session verification failed. Please try again.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user