<commit_before>import React from 'react'
import cookie from 'cookie'
import PropTypes from 'prop-types'
import { getDataFromTree } from 'react-apollo'
import Head from 'next/head'

import initApollo from './initApollo'

function parseCookies(req, options = {}) {
  return cookie.parse(
    req && req.headers.cookie
      ? req.headers.cookie
      : document.cookie,
    options
  )
}

export default App => {
  return class WithData extends React.Component {
    static displayName = `WithData(${App.displayName})`
    static propTypes = {
      apolloState: PropTypes.shape({
        data: PropTypes.object.isRequired
      }).isRequired
    }

    static async getInitialProps(ctx) {
      const { Component, router, ctx: { req, res } } = ctx
      const apolloState = {}
      const apollo = initApollo({}, {
        getToken: () => parseCookies(req).token
      })

      ctx.ctx.apolloClient = apollo

      let appProps = {}
      if (App.getInitialProps) {
        appProps = await App.getInitialProps(ctx)
      }<commit_msg>Fixed error with the cookie parser in with-apollo-auth (#4445)<commit_after>import React from 'react'
import cookie from 'cookie'
import PropTypes from 'prop-types'
import { getDataFromTree } from 'react-apollo'
import Head from 'next/head'

import initApollo from './initApollo'

function parseCookies(req, options = {}) {
  return cookie.parse(
    req ? req.headers.cookie || '' : document.cookie,
    options
  )
}

export default App => {
  return class WithData extends React.Component {
    static displayName = `WithData(${App.displayName})`
    static propTypes = {
      apolloState: PropTypes.shape({
        data: PropTypes.object.isRequired
      }).isRequired
    }

    static async getInitialProps(ctx) {
      const { Component, router, ctx: { req, res } } = ctx
      const apolloState = {}
      const apollo = initApollo({}, {
        getToken: () => parseCookies(req).token
      })

      ctx.ctx.apolloClient = apollo

      let appProps = {}
      if (App.getInitialProps) {
        appProps = await App.getInitialProps(ctx)
      }
{'fraction_non_alphanumeric': 0.1133428981348637, 'fraction_numerical': 0.001912960306073649, 'mean_word_length': 2.9397363465160073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4615964', 'n_tokens_mistral': 638, 'n_tokens_neox': 616, 'n_words': 163}