admin管理员组文章数量:1440487
I'm facing an issue where JWT tokens are not being sent from the client to the server in my production environment. The project consists of a Django REST Framework backend and a Next.js frontend. Everything works fine in the development (127.0.0.1) environment, but in production, the JWT token stored in the cookies is not being sent back to the server.
Project Setup: Backend (Django) Settings: Here are my relevant settings in settings.py:
REST_AUTH = {
'JWT_AUTH_COOKIE': 'token',
'JWT_AUTH_REFRESH_COOKIE': 'refresh_token',
'JWT_AUTH_SECURE': True, # Enabled for production
'JWT_AUTH_HTTPONLY': True,
'JWT_AUTH_SAMESITE': 'None',
}
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [
'', # My frontend domain
]
Frontend (Next.js) Configuration: On the client side, I'm sending requests using fetch as follows:
fetch("/auth/login", {
method: "POST",
credentials: "include", // Ensure cookies are sent
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ username, password })
});
Environment: Frontend URL: Backend URL: Browser: Chrome (latest version) HTTPS is enabled for both frontend and backend.
Why aren't the cookies being sent in subsequent requests? What could be causing this issue, and how can I fix it?
本文标签: JWT token not being sent in production (Django REST Framework amp Nextjs 14)Stack Overflow
版权声明:本文标题:JWT token not being sent in production (Django REST Framework & Next.js 14) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745664407a2669202.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论