'Can't use cookie in frontend but works fine in postman
I've created rest API in springboot that upon sending valid credentials returns jwt access token and saves refresh token in httpOnly cookie, when I send GET request to the API that uses cookie in postman it works just fine but when I try to fetch in react API returns error that indicates that there is no cookies
error_message: "Cannot read the array length because "array" is null"
So do I have to specify domain name If yes how do I do it while working on localhost (springboot is working on localhost:8080 and react localhost:3000).
How I currently create cookie:
public static Cookie createRefreshCookie(String refresh_token) {
Cookie jwtRefreshCookie = new Cookie("refresh_token", refresh_token);
jwtRefreshCookie.setMaxAge(2678400);
jwtRefreshCookie.setHttpOnly(true);
jwtRefreshCookie.setPath("/");
return jwtRefreshCookie;
}
Solution 1:[1]
Problem was caused by my fetch request in react that contained header withCredentials: true from library axios insead of fetch implementation of header credentials:"include".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Grimalkin |
