79188327

Date: 2024-11-14 10:31:52
Score: 0.5
Natty:
Report link

To resolve the "no tokens found in cookies" error when using JWT authentication, ensure the following:

CORS Configuration: The backend should be configured to allow cross-origin requests with credentials (cookies). This is necessary if the frontend and backend are hosted on different domains or ports.

Frontend Request: When making requests from your React app, always include credentials: 'include' in your fetch or axios call to send cookies along with the request.

Correct Cookie Settings: The JWT token should be set in a cookie with the appropriate flags, such as httpOnly, secure, and sameSite: 'None' if working with different origins.

Token Verification: On the backend, make sure you're extracting the JWT token from the cookies and verifying it properly before allowing access to protected routes.

Browser Settings: Ensure that the browser is accepting third-party cookies, especially if you're testing locally with different ports for frontend and backend.

By following these steps, you should be able to properly send, receive, and verify JWT tokens for authentication in your Node.js and React app.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Ravindran Dharshan