admin管理员组文章数量:1123274
I'm working on a Next.js 14 app with Next-Auth configured to use Keycloak as the provider. The entire setup is running in containers managed via Portainer, with the production environment behind a Caddy web server.
While everything works perfectly in my local environment, I'm encountering an issue in production where requests get stuck in a 302 redirect loop during CSRF validation.
Here are the relevant logs:
GET /api/auth/csrf 200 in 14ms POST /api/auth/signin/keycloak 200 in 13ms POST /api/auth/signin/keycloak 200 in 16ms GET /api/auth/signin?csrf=true 200 in 11ms GET /api/auth/signin?csrf=true 200 in 30ms POST /api/auth/signin/keycloak 302 in 37ms GET /api/auth/signin?csrf=true 200 in 23ms
It seems to be continuously redirecting on the CSRF endpoint after a 302.
Local Environment: Works fine, no issues.
Production Environment: Running in containers via Portainer, behind a Caddy web server.
Keycloak and Next-Auth Configuration: Standard setup following the Next-Auth documentation for Keycloak.
I'm wondering if this could be related to:
Cookie handling or CSRF token validation in the production setup.
Caddy server configuration (e.g., headers, proxy settings).
Something specific about running everything in containers under Portainer.
Has anyone encountered a similar issue or have suggestions on how to resolve this? Any pointers or guidance would be greatly appreciated.
this is the caddyconf file
keycloak.mydomain {
reverse_proxy keycloak-dev:8080 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {host}
# header_up X-Forwarded-Proto {scheme}
# header_up X-Forwarded-Host {host}
header_up Forwarded "for={remote};proto={scheme};host={host}"
header_up Upgrade {>Upgrade}
header_up Connection {>Connection}
}
log {
output stdout
level DEBUG
}
}
dashboard.mydomain {
reverse_proxy dashboard-ui-dev:3001 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up Cookie {>Cookie}
header_up Authorization {>Authorization}
header_up CSRF-Token {>CSRF-Token}
header_up X-CSRF-Token {>X-CSRF-Token}
header_up Upgrade {>Upgrade}
header_up Connection {>Connection}
}
log {
output stdout
level DEBUG
}
}
本文标签: nextjsCaddyKeycloak blank page in redirect loginStack Overflow
版权声明:本文标题:next.js - Caddy + Keycloak blank page in redirect login - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736561869a1944655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论