File: frontend/app/(auth)/login/page.jsx
This commit is contained in:
@@ -67,14 +67,19 @@ function LoginForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ✅ ยืนยันว่าเซสชันพร้อมใช้งานก่อน (กัน redirect วน)
|
// ✅ ยืนยันว่าเซสชันพร้อมใช้งานก่อน (กัน redirect วน)
|
||||||
const me = await fetch(`${API_BASE}/api/auth/me`, {
|
// ✅ รอ session ให้พร้อมจริง (retry สูงสุด ~1.5s)
|
||||||
method: "GET",
|
let me = null, ok = false;
|
||||||
credentials: "include",
|
for (let i = 0; i < 5; i++) {
|
||||||
cache: "no-store",
|
me = await fetch(`${API_BASE}/api/auth/me`, {
|
||||||
}).then(r => r.ok ? r.json() : null).catch(() => null);
|
method: "GET",
|
||||||
|
credentials: "include",
|
||||||
if (!me?.ok) {
|
cache: "no-store",
|
||||||
setErr("ล็อกอินสำเร็จ แต่ตรวจสอบเซสชันไม่ผ่าน — โปรดลองใหม่");
|
}).then(r => r.ok ? r.json() : null).catch(() => null);
|
||||||
|
if (me?.ok) { ok = true; break; }
|
||||||
|
await new Promise(r => setTimeout(r, 300)); // เว้นระยะ 300ms
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
setErr("ล็อกอินสำเร็จ แต่ยังไม่เห็นเซสชันจากเซิร์ฟเวอร์ (ลองใหม่หรือตรวจคุกกี้)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user