kandimat/redaktions-app/src/backend/helper.ts
2021-01-09 12:49:28 +01:00

26 lines
637 B
TypeScript

import { ApolloClient, createHttpLink, InMemoryCache } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { getRawJsonWebToken } from "../jwt/jwt";
const httpLink = createHttpLink({
uri: "http://localhost:5433/graphql",
});
const authLink = setContext((_, { headers }) => {
const token = getRawJsonWebToken();
return token
? {
headers: {
...headers,
authorization: `Bearer ${token}`,
},
}
: headers;
});
export const client = new ApolloClient({
cache: new InMemoryCache(),
link: authLink.concat(httpLink),
connectToDevTools: true,
});