1

I have an API in NodeJs where I need to validate a token to let a user pass that middleware and retrieve storeId. I have a cookie with ts key in my localhost : cookie ts in application dev tools

And I have my AJAX call.

$.ajax({
    type:'POST',
    dataType: 'JSON',
    url: 'http://www.localhost:8090/product',
    data: product,
    xhrFields: { withCredentials: true },
    crossDomain: true,
    async: false,
    success: result => {
        console.log(result)
        $('#FormLoading').remove()
    }
})

And for some reason it still doesn't send the token but in other pages like homepage dashboard it works. response

Tyler2P
  • 2,324
  • 26
  • 22
  • 31

1 Answers1

0

The ts key is for localhost domain and you are calling http://www.localhost:8090/product. Normally if the domain of your cookies are like the domain of the API URL, the cookie key and its value will be inserted in the header request automatically as a string series. But here the domain of your cookie is localhost and domain of the API is www.localhost. So AJAX ignores the cookie.You should set the cookie domain with wildcard, when generating cookie in node js server response to login request, or change the base URL of the API to localhost. By the way this may help How do browser cookie domains work?

mahooresorkh
  • 1,361
  • 2
  • 8
  • 16