diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-16 10:54:08 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-16 10:54:08 -0400 |
| commit | 802b65cfd634305f62d88cb57c54f8c053701d27 (patch) | |
| tree | 12a06778d21a8b14bade3ccc8c9dd75f59f97e4a /frontend/pages | |
| parent | 3f9b14e3c1d7f47d9b3e48b94b3b5bf2c722205e (diff) | |
SSR Auth WIP
Diffstat (limited to 'frontend/pages')
| -rw-r--r-- | frontend/pages/_app.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index 8857120..742532f 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -3,19 +3,26 @@ import { ApolloProvider } from 'react-apollo'; import withData from '../lib/withData'; import { CURRENT_USER_QUERY } from '../queries/queries.graphql'; import Page from '../components/Page'; +import cookie from 'cookie'; // Next.js wraps each Page in an <App></App> component. This is handy for when you want to persist anything from page to page, or just access a component that is 1 level higher than each page. // here we use App from next/app and wrap it with withData so we can get Apollo and SSR class MyApp extends App { - componentDidMount() { - if (typeof window !== 'undefined' && !window.__CLIENTLOADED__) { - this.props.apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); - window.__CLIENTLOADED__ = true; - } - } + // componentDidMount() { + // if (typeof window !== 'undefined' && !window.__CLIENTLOADED__) { + // this.props.apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); + // window.__CLIENTLOADED__ = true; + // } + // } static async getInitialProps({ Component, ctx }) { + if (!process.browser && ctx.req.headers.cookie) { + // if we are SSR, pass along the cookie to apollo + console.log('On the server'); + const cookies = cookie.parse(ctx.req.headers.cookie); + console.log(cookies.token); + } let pageProps = {}; if (Component.getInitialProps) { |
