251002 frontend/app/(auth)/login/page.jsx
This commit is contained in:
@@ -66,9 +66,24 @@ function LoginForm() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// คุกกี้ (HttpOnly) ถูกตั้งด้วย Set-Cookie จาก backend แล้ว
|
// ✅ ยืนยันว่าเซสชันพร้อมใช้งานก่อน (กัน redirect วน)
|
||||||
dlog("login ok → redirect", nextPath);
|
const me = await fetch(`${API_BASE}/api/auth/me`, {
|
||||||
router.replace(nextPath);
|
method: "GET",
|
||||||
|
credentials: "include",
|
||||||
|
cache: "no-store",
|
||||||
|
}).then(r => r.ok ? r.json() : null).catch(() => null);
|
||||||
|
|
||||||
|
if (!me?.ok) {
|
||||||
|
setErr("ล็อกอินสำเร็จ แต่ตรวจสอบเซสชันไม่ผ่าน — โปรดลองใหม่");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ ใช้ hard navigation ให้ SSR เห็นคุกกี้แน่นอน
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
window.location.href = nextPath || "/dashboard";
|
||||||
|
} else {
|
||||||
|
router.replace(nextPath || "/dashboard");
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dlog("exception =", e);
|
dlog("exception =", e);
|
||||||
setErr("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้ กรุณาลองใหม่");
|
setErr("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้ กรุณาลองใหม่");
|
||||||
|
|||||||
Reference in New Issue
Block a user