251002 frontend/app/(auth)/login/page.jsx
This commit is contained in:
@@ -66,9 +66,24 @@ function LoginForm() {
|
||||
return;
|
||||
}
|
||||
|
||||
// คุกกี้ (HttpOnly) ถูกตั้งด้วย Set-Cookie จาก backend แล้ว
|
||||
dlog("login ok → redirect", nextPath);
|
||||
router.replace(nextPath);
|
||||
// ✅ ยืนยันว่าเซสชันพร้อมใช้งานก่อน (กัน redirect วน)
|
||||
const me = await fetch(`${API_BASE}/api/auth/me`, {
|
||||
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) {
|
||||
dlog("exception =", e);
|
||||
setErr("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้ กรุณาลองใหม่");
|
||||
|
||||
Reference in New Issue
Block a user