Refactor authentication system: replace NextAuth with custom login/logout/session handling, improve cookie management, and enhance error handling
Build and Push Reader Image / docker (push) Successful in 39s

This commit is contained in:
2026-04-24 01:53:32 +07:00
parent 690a2fbd51
commit 7c4404ded8
26 changed files with 368 additions and 239 deletions
+3 -26
View File
@@ -1,28 +1,5 @@
/**
* Next.js Instrumentation Hook — chạy một lần khi server khởi động.
*
* Mục đích:
* 1. Ép IPv4-first để tránh Happy Eyeballs timeout khi gọi Google OAuth
* (openid-client bên trong NextAuth gọi oauth2.googleapis.com).
* 2. Tắt keep-alive trên global https agent để tránh stale connection:
* Sau lần đăng nhập đầu, connection pool giữ lại TCP socket tới Google.
* NAT/firewall của Docker drop socket này sau vài phút (silently).
* Khi đăng nhập lần 2, openid-client cố reuse socket đã chết → treo 3500ms.
* keepAlive: false buộc mở connection mới mỗi request, không reuse pool cũ.
* Next.js Instrumentation Hook.
* Hiện tại không áp dụng side effects để tránh ảnh hưởng runtime khởi động.
*/
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { setDefaultResultOrder } = await import("dns")
setDefaultResultOrder("ipv4first")
const https = await import("https")
https.globalAgent = new https.Agent({
keepAlive: false,
})
const http = await import("http")
http.globalAgent = new http.Agent({
keepAlive: false,
})
}
}
export async function register() {}