Verify session server-side before redirect
This commit is contained in:
parent
6247bb42bc
commit
480de976ef
1 changed files with 6 additions and 4 deletions
|
|
@ -34,10 +34,12 @@ export default function AdminLoginPage() {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (res.ok && data.success) {
|
if (res.ok && data.success) {
|
||||||
console.log("LoginPage: success, checking cookie before redirect...");
|
// Verify session server-side before redirect
|
||||||
const token = document.cookie.match(/tia_admin_session=([^;]+)/)?.[1];
|
const sessionRes = await fetch("/api/admin/auth");
|
||||||
console.log("LoginPage: cookie token =", token ? "found" : "NOT FOUND");
|
const sessionData = await sessionRes.json();
|
||||||
router.push("/admin");
|
if (sessionData.authenticated) {
|
||||||
|
router.push("/admin");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setError(data.error || "Invalid credentials");
|
setError(data.error || "Invalid credentials");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue