-
Notifications
You must be signed in to change notification settings - Fork 1
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
Set header to SvelteApolloClient #3
Comments
You'll need to pass in a custom fetch function which adds the header. import { SvelteApolloClient } from "svelte-apollo-client";
import { HttpLink } from "@apollo/client/link";
import { InMemoryCache } from "@apollo/client/cache";
import merge from 'merge'
const link = new HttpLink({
uri: "/graphql",
fetch: authenticatedFetch(),
fetchOptions: {
credentials: "include",
},
});
export const client = SvelteApolloClient({
link,
cache: new InMemoryCache(),
});
function authenticatedFetch() {
return (uri, options) => {
fetch(uri, merge(options, {
headers: {
Authorization:
`Bearer {authToken}`,
}
}))
}
} |
Better examples in the docs |
@unlocomqx Can you provide a full project example? I'm sure this is common enough that a full breakdown would really help as I am too struggling with setting the auth token. The apollo docs don't provide a relevant enough example to achieve this in sveltekit. |
Check the code here, it shows how to make an auth'd graphql request |
I have application with JWT authentication, and i want to set header after login. This is my code :
How can i dynamically change the header Authorization?
The text was updated successfully, but these errors were encountered: