0

When your backend is deployed to aws and you have to develop http cookie authentication to a locally hosted reactjs frontend how do you implement it?

The issue is..

When I call the login API endpoint it's supposed to set a http-only cookie to my browser but it doesn't.

I've mentioned my axios intecepter below incase if it's the issue. If you can suggest me a solution that would be great.

ps : the backend doesn't have a issue, When i call the login endpoint with postman. relevant cookies are setting automatically

export const axiosHttp = axios.create({
  headers: { "Content-Type": "application/json" },
  withCredentials: true,
});

axiosHttp.interceptors.response.use(
  (response) => response,
  async (error) => {
    const prevRequest = error?.config;
    if (error.response.status === 401 && !prevRequest?.sent) {
      prevRequest.sent = true;
      const res = await refreshToken();
      console.log(res);
      return axiosHttp(prevRequest);
    }
    return Promise.reject(error);
  }
);
3
  • What are you using in the backend, it's not related to AWS, just set http-only on your backend technology. Commented Mar 28, 2024 at 10:47
  • @quyentho it's a express backend. i dont think it's a backend issue since the cookies works as it suppose to work when i test the apis on postman but with the frontend (locally hosted) it wont work. Commented Mar 28, 2024 at 17:39
  • How can you be sure it's not working on the frontend? Have you checked the developer tools (devtools)? If you can, could you edit your question to include the response containing the HttpOnly cookie when you make the request using Postman? Commented Mar 28, 2024 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.