1

I am using Apollo Client in my React app.

When a user is logged-in in our cms we set a HttpOnly cookie. I can see in my React app (browser) when I inspect with devtools this cookie has been set: MYNAMEffb4afd023baac83115bf7882.

I need to send a custom Request header to each GraphQl query request. But only when above cookie has been set.

The custom header:

X-My-Name: Name

What are the steps I have to follow?

9
  • This can be done in a link Commented Oct 29, 2022 at 17:36
  • @MichelFloyd thanks! But how do I check in React if HttpOnly cookie has been set? So in the custom link I can add an if statement if (hasMyHttpOnlyCookie) {// link code}. As far as I know you can't read an HttpOnly cookie in your frontend? Otherwise it will send that request header all the time in every GraphQL request. Also for 'normal' users? Commented Oct 30, 2022 at 7:25
  • stackoverflow.com/a/63877877/2805154 Commented Oct 30, 2022 at 19:07
  • @MichelFloyd thanks again. So if I am not mistaken, the way to go is setting another non-httponly cookie as explained here. Is that correct? Commented Oct 30, 2022 at 21:16
  • That's one way. Or you could avoid cookies altogether and use custom headers and local storage. Commented Oct 30, 2022 at 23:17

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.