diff options
Diffstat (limited to 'frontend/pages/_app.js')
| -rw-r--r-- | frontend/pages/_app.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index 27202d5..b23df9b 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -1,13 +1,19 @@ -import App, { Container } from 'next/app'; -import React from 'react'; import { ApolloApp } from 'next-with-apollo'; import withData from '../lib/withData'; +import { CURRENT_USER_QUERY } from '../queries/queries'; // 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. -// This code is taken right from the Next.js docs, and then we add the Router to the page props, which is why we need a custom _app.js +// normall here you import App from next/app, but we use next-with-apollo's ApolloApp here so we can get SSR class MyApp extends ApolloApp { + componentDidMount() { + if (typeof window !== 'undefined' && !window.__CLIENTLOADED__) { + console.log('Refetching current user'); + this.props.apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); + window.__CLIENTLOADED__ = true; + } + } static async getInitialProps({ Component, ctx }) { let pageProps = {}; @@ -15,7 +21,7 @@ class MyApp extends ApolloApp { pageProps = await Component.getInitialProps(ctx); } - pageProps.query = ctx.query + pageProps.query = ctx.query; return { pageProps }; } |
