kandimat/redaktions-app/src/backend/helper.ts
2020-12-31 11:36:23 +01:00

25 lines
602 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,
});