diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-15 11:01:32 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-15 11:01:32 -0400 |
| commit | 4daef52d648db9953e68fa99495db047833a4ad9 (patch) | |
| tree | 88257aa26c3ca9bcd3188f5f0cb680befc64fe31 /frontend/pages/_app.js | |
| parent | a87f7f9b49a8de91f8c65476c9badccc2c4c69c6 (diff) | |
move user check to _app
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 }; } |
