Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ApolloLink } from 'apollo-link';
- import { HttpLink } from 'apollo-link-http';
- import { API_URL } from '~/utils';
- export default (ctx) => {
- const httpLink = new HttpLink({ uri: `${API_URL}/graphql` });
- // auth token
- // middleware
- const middlewareLink = new ApolloLink((operation, forward) => {
- const token = ctx.isServer ? ctx.req.session.token : window.__NUXT__.state.auth.token;
- if (token) {
- operation.setContext({
- headers: { Authorization: `JWT ${token}` },
- });
- }
- return forward(operation);
- });
- const link = middlewareLink.concat(httpLink);
- return {
- link,
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement