qwik
qwik copied to clipboard
feat: add useRequestHeaders hook
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
-
- 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.
- SPAs that use a GraphQL API that want to make use of SSR without adding onGet(/etc) methods will use the
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