Skip to content

Instantly share code, notes, and snippets.

@brunocrosier
Created February 21, 2021 19:25
Show Gist options
  • Save brunocrosier/825688b5cd7a25fce88f2c6f30bca547 to your computer and use it in GitHub Desktop.
Save brunocrosier/825688b5cd7a25fce88f2c6f30bca547 to your computer and use it in GitHub Desktop.
Mock _app.tsx file for next-auth + apollo
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