qwik icon indicating copy to clipboard operation
qwik copied to clipboard

feat: add useRequestHeaders hook

Open DustinJSilk opened this issue 3 years ago • 0 comments

What is it?

  • [X] Feature / enhancement
  • [ ] Bug
  • [ ] Docs / tests

Description

I've added a new hook to Qwik City to expose request headers during SSR - useRequestHeaders

This hook can be used by applications that rely on external APIs that require authentication tokens. Tokens can be stored as a cookie and then retrieved during SSR in a useResource$ hook and passed on to the API.

Currently, the only way to access headers is in the onGet methods.

Use cases and why

    1. SPAs that use a GraphQL API that want to make use of SSR without adding onGet(/etc) methods will use the useResource$ hook to run queries from both environments but need to forward the access tokens onto the API.

Checklist:

  • [X] My code follows the developer guidelines of this project
  • [X] I have performed a self-review of my own code
  • [ ] I have made corresponding changes to the documentation
  • [ ] Added new tests to cover the fix / functionality

DustinJSilk avatar Oct 06 '22 13:10 DustinJSilk