pass headers to initializeApollo (nginx injects Authorization header to any request)
This commit is contained in:
parent
13cd93338f
commit
16b7188773
@ -2,7 +2,6 @@
|
||||
import { message } from '@/Components/Common/Notification';
|
||||
import { publicRuntimeConfigSchema } from '@/config/schema/runtime-config';
|
||||
import getUrls from '@/config/urls';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { ApolloLink, from, HttpLink } from '@apollo/client';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
@ -81,12 +80,10 @@ export function createLink(headers) {
|
||||
}
|
||||
|
||||
if (isServer()) {
|
||||
const token = getToken({ headers });
|
||||
|
||||
return {
|
||||
headers: {
|
||||
...existingHeaders,
|
||||
authorization: `Bearer ${token}`,
|
||||
authorization: headers.authorization,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ export async function getServerSideProps({ req }) {
|
||||
const { cookie = '' } = req.headers;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const apolloClient = initializeApollo(null, { cookie });
|
||||
const apolloClient = initializeApollo(null, req.headers);
|
||||
const getUserType = makeGetUserType({ apolloClient, queryClient });
|
||||
|
||||
try {
|
||||
|
||||
@ -36,7 +36,7 @@ export async function getServerSideProps({ req }) {
|
||||
const { cookie = '' } = req.headers;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const apolloClient = initializeApollo(null, { cookie });
|
||||
const apolloClient = initializeApollo(null, req.headers);
|
||||
const getUserType = makeGetUserType({ apolloClient, queryClient });
|
||||
|
||||
try {
|
||||
|
||||
@ -37,7 +37,7 @@ export async function getServerSideProps({ req }) {
|
||||
const { cookie = '' } = req.headers;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const apolloClient = initializeApollo(null, { cookie });
|
||||
const apolloClient = initializeApollo(null, req.headers);
|
||||
const getUserType = makeGetUserType({ apolloClient, queryClient });
|
||||
|
||||
try {
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
import type { IncomingHttpHeaders } from 'http';
|
||||
|
||||
type Request = {
|
||||
headers: IncomingHttpHeaders;
|
||||
};
|
||||
|
||||
export function getToken({ headers }: Request) {
|
||||
return headers.cookie
|
||||
?.split(';')
|
||||
.find((c) => c.trim().startsWith('token='))
|
||||
?.split('=')[1];
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user