Created
February 21, 2021 19:25
-
-
Save brunocrosier/825688b5cd7a25fce88f2c6f30bca547 to your computer and use it in GitHub Desktop.
Mock _app.tsx file for next-auth + apollo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloProvider } from "@apollo/client"; | |
import Layout from "components/Layout"; | |
import { useApollo } from "lib/apolloClient"; | |
import { Provider as NextAuthProvider } from "next-auth/client"; | |
import { AppProps } from "next/app"; | |
import "./styles.css"; | |
const App = ({ Component, pageProps }: AppProps) => { | |
const { session } = pageProps; | |
const apolloClient = useApollo(pageProps.initialApolloState, session?.token); | |
return ( | |
<NextAuthProvider session={session}> | |
<ApolloProvider client={apolloClient}> | |
<Layout> | |
<Component {...pageProps} /> | |
</Layout> | |
</ApolloProvider> | |
</NextAuthProvider> | |
); | |
}; | |
// The below code allows us to access `session` but it opts us out of SSG | |
// App.getInitialProps = async ({ Component, ctx, router }: AppContext) => { | |
// const session = await getSession(ctx); | |
// let pageProps = {}; | |
// if (Component.getInitialProps) { | |
// pageProps = await Component.getInitialProps(ctx); | |
// } | |
// return { | |
// pageProps: { ...pageProps, session }, | |
// }; | |
// }; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment