Skip to content

Cookies not sent to Server  #4455

Closed
Closed
@coommark

Description

@coommark

Intended outcome:
I have three (3) applications proxied by express-http-proxy to port 8080. Each is running on a different port. Two of them are react (NextJS) frontend and admin apps. User must log in from the frontend before access to backend. The apollo-client setup for both of the UI apps are exactly the same, below:

import withApollo from 'next-with-apollo'
import ApolloClient, { InMemoryCache } from 'apollo-boost'

export default withApollo(({ ctx, headers, initialState }) => (
  new ApolloClient({
    uri: "http://localhost:8080/api/graphql",
    cache: new InMemoryCache().restore(initialState || {})
  })
))

When a user logs in, I push their token to cookies so it can be sent back to the graphql api. This works with the actual app that the user authenticates on, but when I navigate to the backend app, the cookies are not sent.

In devtools I can see that the cookies are there alright, but they just don't get sent with requests.

I have tried this, but still, all cookies are not sent to server:

import withApollo from 'next-with-apollo'
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { onError } from 'apollo-link-error';
import { ApolloLink } from 'apollo-link';

export default withApollo(({ ctx, headers, initialState }) => (
    new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      uri: "http://localhost:8080/api/graphql"
    }),
    request: async operation => {
    operation.setContext({
      fetchOptions: {
        credentials: 'include'
      }
    });
  }
})
))

I have tried other variations of these. Note that when I use http://localhost:8080/api/graphql the cookies are sent ok since they all point to 8080, but when I send request via apollo-client, the cookies are not sent to the server.

Versions

"apollo-boost": "^0.1.27",
    "apollo-cache-inmemory": "^1.4.3",
    "apollo-client": "^2.4.13",
    "apollo-link": "^1.2.8",
    "apollo-link-error": "^1.1.7",
    "apollo-link-http": "^1.5.11",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions