Skip to content

Commit 90e1e97

Browse files
committed
fix: send cookies to the server by getting from next
1 parent a463d7d commit 90e1e97

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/graphql/clients/clientSideMakeClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { from } from '@apollo/client';
1+
import { HttpLink, from } from '@apollo/client';
22
import {
33
NextSSRApolloClient,
44
NextSSRInMemoryCache,
55
SSRMultipartLink,
66
} from '@apollo/experimental-nextjs-app-support/ssr';
7-
import { createErrorLink, httpLink } from '../utils';
7+
import { createErrorLink } from '../utils';
8+
9+
const httpLink = new HttpLink({
10+
uri: process.env.NEXT_PUBLIC_GATEWAY_URL,
11+
});
812

913
export const makeClient = () => {
1014
return new NextSSRApolloClient({

src/graphql/clients/serverSideClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import { ApolloClient, InMemoryCache, from } from '@apollo/client';
1+
import { ApolloClient, HttpLink, InMemoryCache, from } from '@apollo/client';
22
import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc';
3-
import { httpLink } from '../utils';
3+
import { cookies } from 'next/headers';
44

55
export const { getClient } = registerApolloClient(() => {
6+
const cookiesStore = cookies();
7+
8+
const httpLink = new HttpLink({
9+
uri: `${process.env.__NEXT_PRIVATE_ORIGIN}${process.env.NEXT_PUBLIC_GATEWAY_URL}`,
10+
headers: {
11+
cookie: cookiesStore.toString(),
12+
},
13+
});
14+
615
return new ApolloClient({
16+
ssrMode: true,
717
cache: new InMemoryCache(),
818
connectToDevTools: true,
919
link: from([httpLink]),

src/graphql/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { HttpLink } from '@apollo/client';
21
import { onError } from '@apollo/client/link/error';
32
import { Observable } from '@apollo/client/utilities';
43
import { toast } from 'react-toastify';
54

6-
export const httpLink = new HttpLink({
7-
uri:
8-
typeof window !== 'undefined'
9-
? process.env.NEXT_PUBLIC_GATEWAY_URL
10-
: `${process.env.__NEXT_PRIVATE_ORIGIN}${process.env.NEXT_PUBLIC_GATEWAY_URL}`,
11-
});
12-
135
export const createErrorLink = () => {
146
return onError(({ graphQLErrors, operation, forward }) => {
157
const targetErrors = [

0 commit comments

Comments
 (0)