New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for updating headers #87
Comments
You have multiple options today: Option 1 (Cookies): import { KitQLClient } from '@kitql/client';
export const kitQLClient = new KitQLClient({
url: '.../graphql',
credentials: 'include',
}); Options 2 (manual Authorization): import { KitQLClient } from '@kitql/client';
export const kitQLClient = new KitQLClient({
url: '.../graphql',
headers: {
Authorization: `Bearer ${TOKEN}`
},
}); Are you looking for something else? |
Thanks for the quick response! Isn't both of these cases when initializing the client? What if you want to update the client and not create a new one? |
With option 1, you work with cookies. For option 2, yes, it's only once today. You would like to be able to update headers globally only? and/or at query each request as well? |
|
I'll add it in the coming days and let you check 👍 |
@AlexanderBacklund what if I make import { KitQLClient} from '@kitql/client';
//cool stuff to have it typed 🤟
export type AppHeaders = {
Authorization: `Bearer ${string}`;
};
const defaultHeaders: AppHeaders = null;
export const kitQLClient = new KitQLClient({
url: `https://countries.trevorblades.com/graphql`,
headersContentType: 'application/json',
headers: defaultHeaders,
logType: ['client', 'server', 'operationAndvariables'],
}); And in your code, do something like: <script lang="ts">
function updateHeaders() {
(kitQLClient.headers as AppHeaders) = { Authorization: 'Bearer MY_TOKEN' };
}
</script>
<button on:click={updateHeaders}>Update Headers</button> Let me know |
Hi again! Yes, that is one way to do it (how I did it locally to continue my work) but personally I prefer getter and setter or do you see any drawbacks in doing it that way? |
Should be in |
Hi!
Is there a way to update the headers for the kitQl client? For now I just added a setter/adder method for the kitQl header. My goal is to login and add a jwt token to the header.
The text was updated successfully, but these errors were encountered: