Cookie is not seting in the browser

I have created a Java full-stack Instagram clone in which I am using JWT token authentication but due to some issues, the token sent by the backend is not storing it in the frontend.

For example, my spring boot application is running on localhost:8080, a MongoDB container is running on localhost:3000 and my frontend application (NextJs) is running on localhost:3001. In Postman I can see that the sign-in controller is sending the token with the `set-cookie` header but somehow the frontend is not storing it. I have confirmed it by inspecting in dev tools under the application under the cookie section. There is no cookie.

I have the following cookie configuration in my spring-boot application:

Cookie cookie = new Cookie("Authorization",token);
cookie.setHttpOnly(true);
cookie.setPath("/");
cookie.setDomain("localhost");

cookie.setSecure(false);
response.addCookie(cookie);

I tried to research this on Google, some suggested using a cookie package in the frontend. I used it but still no luck. I am not able to store a single cookie on the frontend. I don't know why it's not storing the cookies in the frontend.

I am not getting what I am doing wrong. I have been stuck on it for 2 weeks.