Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot send httponly cookie to express server from react js

I am working on a react app which receives httponly cookie from third party website.

I am able to see the cookie in Chrome developer console. I am trying to send this cookie to backend of my app, built in expressjs, so that I can read the cookie. I am using fetch to send a GET request to the app while including the prop below:

Credentials: 'include' 

In the express server, am allowing my front-end inside CORS and also set credentials equal to true.

Issue:
In request header of my express server, I can't see the httponly cookie.

Can anyone guide me how can I send httponly and get it inside express server?

like image 536
bhanu Avatar asked Jun 16 '26 17:06

bhanu


1 Answers

On client you must enable credentials as well. There is axios module to make requests with credentials. Example of usage:

import axios from 'axios'

const instance = axios.create({
  withCredentials: true,
  baseURL: API_SERVER
})

instance.get('todos')

In other way, you could provide cookie with XMLHttpRequest:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/', true);
xhr.withCredentials = true;
xhr.send(null);

XMLHttpRequest

like image 76
user14080657 Avatar answered Jun 19 '26 11:06

user14080657



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!